Python builds error lines with different values above and below point
Warning: I am very new to using python.
I am trying to display data using error bars, but my data has different meanings for error above and below the row, i.e. 2 + .75.2-.32.
import numpy as np
import matplotlib.pyplot as plt
# example data
x = (1,2,3,4)
y = (1,2,3,4)
# example variable error bar values
yerr = 0.2
plt.figure()
plt.errorbar(x, y, yerr,"r^")
plt.show()
But I want the error line above point to be a specific value, like .17, and below point to be a specific point, like .3 Does anyone know how to do this?
Thank!
source to share
Like this:
plt.errorbar(x, y, np.array([[0.3]*len(x), [0.17]*len(x)]), fmt='r^')
Pass an array of the form (2,n)
with -errors on the first line and + errors on the second.
(Note that you need to explicitly pass the format string r^
to the argument fmt
).
If you need different error lines at each point, you can pass them in this array (2,n)
. Typically you have a list of -err and + err value pairs for each data point, in which case you can construct the required array as a transposition of that 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 .
source to share