Search code examples
pythonerrorbar

Plotting errorbar plot in Python


How can I plot an errorbar plot in python, having for y different errors up and down? I have x,y, and the values for each error in different lists. I tried this but it doesn't work:

plt.errorbar(x,y,[std_y_down,std_y_up],"r^")

Solution

  • The error you probably got is reasonably informative:

    ValueError: yerr must be a scalar, the same dimensions as y, or 2xN.
    

    In other words, if you want different plus and minus errors you need a pair of sequences, each of the same length as your data e.g.:

    plt.errorbar(x,y,yerr=[[0.5]*len(x),[1.5]*len(x)],fmt='r^')
    

    enter image description here