Use MatPlotLib to build a line graph with error ranges around points

I am trying to build a line graph of ten values ​​with error ranges for each point:

u = [1,2,3,4,5,6,7,8,9,10]
plt.errorbar(range(10), u, yerr=1)
plt.show()

I get an error

ValueError: too many values to unpack

Can someone please advise me the best way to build a line graph with errors over each point? http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.errorbar

THX

+4
source share
1 answer

plt.errorbar expects errors to have the same dimension as x- and y-values ​​(either a list of 2 tuples for up / down errors, or a simple list for symmetric errors).

Do 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))
+3

Source: https://habr.com/ru/post/1530968/


All Articles