Kyle Hunter - 1 year ago 175
Python Question

# Plotting asymmetric error bars Matplotlib

So I have three sets of data:

``````min_data = np.array([ 0.317, 0.312, 0.305, 0.296, 0.281, 0.264, 0.255,
0.237, 0.222, 0.203, 0.186, 0.17, 0.155, 0.113, 0.08])

avg_data = np.array([ 0.3325, 0.3235, 0.3135, 0.30216667, 0.2905, 0.27433333,
0.26116667, 0.24416667, 0.22833333, 0.20966667, 0.19366667, 0.177,
0.16316667, 0.14016667, 0.097])

max_data = np.array([ 0.346, 0.331, 0.32, 0.31, 0.299, 0.282, 0.266, 0.25,
0.234, 0.218, 0.204, 0.187, 0.175, 0.162, 0.115])
``````

I need to plot this data with error bars.

I have attempted:

``````x = np.linspace(0, 100, 15)
err = [min_data, max_data]
plt.errorbar(x, avg_data, 'bo', yerr=err)

TypeError: errorbar() got multiple values for argument 'yerr'
``````

The final graph should look like this:

``````plt.plot(x[::-1], avg_data, 'ro')
plt.plot(x[::-1], min_data, 'bo')
plt.plot(x[::-1], max_data, 'bo')
``````

Where the blue points represent where the error bars should be located.

All the documentation I have been able to find only allows asymmetric errors that is equal in + and - y directions.

Thank you

Your code is failing because it thinks that `'bo'` is the `yerr` argument since the third argument in `plt.errorbar` is `yerr`. If you want to pass the format specifier, then you should use the `fmt` keyword.
``````plt.errorbar(x, avg_data, fmt='bo', yerr=err)