Skip to content Skip to sidebar Skip to footer

Python Matplotlib Errorbar Issue

Given these numpy arrays x = [0 1 2 3 4 5 6 7 8 9] y = [[ 0. ] [-0.02083473] [ 0.08819923] [ 0.9454764 ] [ 0.80604627] [ 0.82189822] [ 0.736139

Solution 1:

There were some problems with the code which I corrected below and so it works with no problem.

import numpy
import pylab

arr = numpy.asarray

x = arr([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])   # put comma between numbers
y = arr([[ 0.        ],                   # make it vector
     [-0.02083473],
     [ 0.08819923],
     [ 0.9454764 ],
     [ 0.80604627],
     [ 0.82189822],
     [ 0.73613942],
     [ 0.64519742],
     [ 0.56973868],
     [ 0.612912  ]]).flatten()
c = arr([[ 0.        ,  0.        ],
     [-0.09127286,  0.04960341],
     [-0.00300709,  0.17940555],
     [ 0.82319693,  1.06775586],
     [ 0.74512774,  0.8669648 ],
     [ 0.75177669,  0.89201975],
     [ 0.63606087,  0.83621797],
     [ 0.57786173,  0.7125331 ],
     [ 0.46722312,  0.67225423],
     [ 0.54951714,  0.67630685]]).T      # transpose
pylab.errorbar(x, y, yerr=c)
pylab.show()

and the result:

enter image description here

Good luck.

Post a Comment for "Python Matplotlib Errorbar Issue"