2014-03-12 69 views

回答

10
>>> import matplotlib.pyplot as plt 
>>> a = [1,3,5,7] 
>>> b = [11,-2,4,19] 
>>> plt.pyplot.scatter(a,b) 
>>> plt.scatter(a,b) 
<matplotlib.collections.PathCollection object at 0x00000000057E2CF8> 
>>> plt.show() 
>>> c = [1,3,2,1] 
>>> plt.errorbar(a,b,yerr=c, linestyle="None") 
<Container object of 3 artists> 
>>> plt.show() 

,其中一個是你的X數據 b爲您的Y數據 C是Y誤差,如果任何

注意,c各自方向上的錯誤已經

7

這是幾乎像其他答案,但你並不需要在所有的一scatter的情節,你可以簡單地爲errorbar指定散點圖樣的格式(fmt -parameter):

import matplotlib.pyplot as plt 
x = [1, 2, 3, 4] 
y = [1, 4, 9, 16] 
e = [0.5, 1., 1.5, 2.] 
plt.errorbar(x, y, yerr=e, fmt='o') 
plt.show() 

結果:

enter image description here

的繳費fmt參數的列表可以例如plot文檔中找到:

character description 
'-'  solid line style 
'--' dashed line style 
'-.' dash-dot line style 
':'  dotted line style 
'.'  point marker 
','  pixel marker 
'o'  circle marker 
'v'  triangle_down marker 
'^'  triangle_up marker 
'<'  triangle_left marker 
'>'  triangle_right marker 
'1'  tri_down marker 
'2'  tri_up marker 
'3'  tri_left marker 
'4'  tri_right marker 
's'  square marker 
'p'  pentagon marker 
'*'  star marker 
'h'  hexagon1 marker 
'H'  hexagon2 marker 
'+'  plus marker 
'x'  x marker 
'D'  diamond marker 
'd'  thin_diamond marker 
'|'  vline marker 
'_'  hline marker