Search code examples
pythonmatplotlibscatter-ploterrorbar

Scatter plot error bars (the error on each point is unique)


I am attempting a scatter plot of 2 arrays for which I have a third array containing the absolute error (error in y direction) on each point. I want the error bars to between (point a - error on a) and (point a + error on a). Is there a way of achieving this with pylab and if not any ideas on how else I could do it?


Solution

  • >>> import matplotlib.pyplot as plt
    >>> a = [1,3,5,7]
    >>> b = [11,-2,4,19]
    >>> plt.pyplot.scatter(a,b)
    >>> plt.scatter(a,b)
    <matplotlib.collections.PathCollection object at 0x00000000057E2CF8>
    >>> plt.show()
    >>> c = [1,3,2,1]
    >>> plt.errorbar(a,b,yerr=c, linestyle="None")
    <Container object of 3 artists>
    >>> plt.show()
    

    where a is your x data b is your y data c is your y error if any

    note that c is the error in each direction already