2016-10-25 49 views
-1

我想绘制一个不同的错误每个点的图形,独立的价值。与Matplotlib不同的错误

我的代码是在这里:

import matplotlib.pyplot as plt 
x=[1,2,3,4,5,6] 
y=[10,20,30,40,50,60] 
errorx=[0.1,0.3,0.7,0.6,1,1.5,0.2] 
errory=[0.1,0.8,0.4,2.3,0.1,1.2,0.6] 
plt.errorbar(x,y,yerr=None,xerr=None) 
plt.plot(x,y) 

我没有得到我想要的东西;我希望没有连接点和x和y误差线的线

+0

欢迎#1。如果您向我们展示您迄今所做的工作,则您更有可能得到答案。一个好的开始是看看matplotlib [documentation](http://matplotlib.org/)。 –

+0

'import matplotlib.pyplot plt x = [1,2,3,4,5,6] y = [10,20,30,40,50,60] errorx = [0.1,0.3,0.7,0.6 ,1,1.5,0.2] errory = [0.1,0.8,0.4,2.3,0.1,1.2,0.6] plt.errorbar(x,y,yerr = None,xerr = None)012tplt.plot(x,y) “到目前为止,我做了什么,然而,我没有得到我想要的。我希望没有连接点和x和y错误栏的线 – MatMorPau22

+1

将您的代码放入问题并正确格式化。如果你把yerr = None,那么就不会有任何错误条。看看[这个例子](http://matplotlib.org/1.2.1/examples/pylab_examples/errorbar_demo.html)了解如何使用这个函数。 – ImportanceOfBeingErnest

回答

1

首先,您在示例中设置了yerrxerr等于None(因为您的评论中显示),因此不会显示错误栏。其次,你的x和y错误列表与你的x和y坐标的长度不一样。因此,如果您尝试绘制此图,您将得到ValueError: xerr must be a scalar, the same dimensions as x, or 2xN.,同样的情况也会发生在您的y错误上。错误栏文档可以找到here

使用数据的一个工作示例如下所示:

import matplotlib.pyplot as plt 

x = [1,2,3,4,5,6] 
y = [10,20,30,40,50,60] 

errorx = [0.1,0.3,0.7,0.6,1,1.5] #now the same length as x and y 
errory = [0.1,0.8,0.4,2.3,0.1,1.2] 

plt.errorbar(x, y, yerr=errory, xerr=errorx, linestyle='') 
#change linestyle to not connect the points 

plt.show() 

这将产生以下图:

enter image description here