Why is pandas applying the same values on both sides of an asymmetric error bar?

后端 未结 1 871
说谎
说谎 2020-12-11 18:18

I\'m trying to plot a series with asymmetric error bars using pandas and matplotlib with the following code:

d = {\'high_delta\': {1: 0.6,
  2: 0.1,
  3: 0.2         


        
相关标签:
1条回答
  • 2020-12-11 18:30

    Short answer: Use 1x2xN shaped error lists for asymmetric error bars.

    F.ex. in the current example use

    errors = [ f.index.values, df['p_hat'].values ]
    df['p_hat'].plot(yerr=[errors])
    

    There is currently a bug in Pandas which results in pandas to interpret error bars given in shape 2xN for a series the same way it would interpret multiple error bars for multiple rows of a DataFrame. Since you are obviously plotting only 1 row/series only the first element of the error bars list is used and interpreted as symmetrical errors.

    Until the bug is fixed in pandas one can "trick" pandas into using asymmetric errors bars by passing errors in the shape of Mx2xN as is the shape expected for asymmetric error bars on DataFrames. To be precise you have to use a 1x2xN shaped list, which can be simply created by calling f.ex. yerr=[ ... ]

    0 讨论(0)
提交回复
热议问题