Skip to content Skip to sidebar Skip to footer

Python Plotting Error Bars With Different Values Above And Below The Point

Warning: I'm very new to using python. I'm trying to graph data using error bars but my data has different values for the error above and below the bar, i.e. 2+.75,2-.32. import n

Solution 1:

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.

enter image description here

(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()

enter image description here

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

Post a Comment for "Python Plotting Error Bars With Different Values Above And Below The Point"