python - How to format errorbars in matplotlib -
i importing data file pandas dataframe , want graph data errorbars. here code:
y = df['pp04-o3n2snpos log(o/h)+12'] - df['nuclear metallicity'] yerr = np.array([df['negative error!'],df['positive error!']]).t x = df['ned calculated virgo infall distance in kpc'] plt.errorbar(x,y,yerr,fmt = 'r^') plt.xlabel('distance center in kpc') plt.ylabel('pp04-o3n2snpos log(o/h)+12') plt.title('central metallicity vs sn metallicity') plt.show()
as can see, format of errorbars on graph messed up. i'm not sure why isn't plotting normal errorbars, instead lines randomly placed.
your problem shape of yerr
array. documentation says array should nx1
array or 2xn
array. yerr
array has nx2
shape.
replace second line with
# create 2xn array error bars yerr = np.array([df['negative error!'],df['positive error!']])
and should ok
Comments
Post a Comment