Python plotting error bars with different values above and below the point

末鹿安然 提交于 2019-12-01 05:19:00

Like this:

plt.errorbar(x, y, np.array([[0.3]*len(x), [0.17]*len(x)]), fmt='r^')

Pass an array of shape (2,n) with the -errors on the first row and the +errors on the second.

(Note also that you need to explicitly pass your format string r^ to the fmt argument).

If you want different error bars on each point, you can pass them in this (2,n) array. You typically have a list of -err and +err value pairs for each data point in order, in which case you can build the necessary array as the transpose of this list:

yerr = np.array([(0.5,0.5), (0.3,0.17), (0.1, 0.3), (0.1,0.3)]).T
plt.errorbar(x, y, yerr, fmt='r^')
plt.show()

This is described (more-or-less) in the docs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!