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() 

however, graph looks enter image description here

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

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -