5

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

1 Answer 1

4

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))
Sign up to request clarification or add additional context in comments.

2 Comments

Note that the stackoverflow way of saying Thank you is accepting helpful answers which you should consider if you want to continue receiving answers to your questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.