I'm trying to plot a line graph of ten values with error ranges over each point:
u = [1,2,3,4,5,6,7,8,9,10]
plt.errorbar(range(10), u, yerr=1)
plt.show()
I get the error message
ValueError: too many values to unpack
Can someone please advise me the best way to plot a line graph with error bars over each point? http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.errorbar
thx
plt.errorbar
expects the errors to have the same dimension as the x- and y-values (either a list of 2-tuples for up/down errors or a simple list for symmetric errors).
You want to do something like
u = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
plt.errorbar(range(10), u, yerr=[1]*10)
or more clearly with numpy imported as np
u = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
plt.errorbar(np.arange(10), u, yerr=np.ones(10))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With