简体   繁体   English

无意中在 matplotlib 中绘制多条线

[英]Unintentionally plotting multiple lines in matplotlib

I am still getting familiar with the matplotlib library and I'm encountering a problem I've never had before.我仍然熟悉 matplotlib 库,但遇到了一个以前从未遇到过的问题。 My intention is to graph the relative error associated with the scipy.integrate.quadrature method as a function of its tolerance value.我的目的是将与scipy.integrate.quadrature方法相关的相对误差绘制为 function 的公差值。 What I'm encountering when I plot it, however, are two distinct lines from the same plt.plot command.但是,当我使用 plot 时,我遇到的是来自同一 plt.plot 命令的两条不同的行。 How did this happen?这怎么发生的? I'll put my code in below.我会把我的代码放在下面。

from scipy import integrate

def f(x):<br/>
    return np.sqrt(1 - x**2)<br/>

xlist = []<br/>
for i in range (-12, 0):<br/>
    xlist.append(i)<br/>

tolerancelist = []<br/>
for i in xlist:<br/>
    tolerancelist.append(10**i)<br/>

ylist = []<br/>
for i in tolerancelist:<br/>
    q = integrate.quadrature(f, -1, 1, tol=i)<br/>
    ylist.append(q)<br/>
       
plt.plot(tolerancelist, ylist, label='line1')<br/>
legend = plt.legend(loc='best')

If you print ylist, you'll get a better understanding of what is going on.如果您打印 ylist,您将更好地了解正在发生的事情。

[(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07),
(1.5708087325834776, 9.6666040283466259e-07), 
(1.5708599005218433, 8.8700570273214652e-06), 
(1.571132830068839, 8.7760917619084111e-05), 
(1.5721552241258274, 0.00062673127406376317),
(1.5759063348593505, 0.0043711928407235145), 
(1.5916172578151968, 0.041375904040254818)]

Each value in ylist is actually tuple of two values. ylist 中的每个值实际上是两个值的元组。 Matplotlib is plotting both as two separate lines. Matplotlib 将两者绘制为两条单独的线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM