use*_*782 25 python matplotlib
我正在尝试一个2个数组的散点图,我有一个第三个数组,包含每个点上的绝对误差(y方向的误差).我希望误差条介于两者之间(点a - a上的错误)和(指向a上的a +错误).有没有办法用pylab实现这一点,如果没有任何想法我怎么能做到这一点?
MSe*_*ert 30
这几乎就像另一个答案,但你根本不需要一个scatter情节,你可以简单地指定一个类似散点图的格式( - fmt参数)errorbar:
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()
Run Code Online (Sandbox Code Playgroud)
结果:
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
Run Code Online (Sandbox Code Playgroud)
270*_*ohn 17
>>> 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()
Run Code Online (Sandbox Code Playgroud)
其中a是你的x数据b是你的y数据c是你的y错误,如果有的话
请注意,c是每个方向的错误
| 归档时间: |
|
| 查看次数: |
78532 次 |
| 最近记录: |