Why does pandas apply the same values ​​on both sides of the asymmetric error bar?

I am trying to build a series with asymmetric error columns using pandas and matplotlib with the following code:

d = {'high_delta': {1: 0.6, 2: 0.1, 3: 0.2, 4: 0.1, 5: 0.1, 6: 0.1, 7: 0.1, 8: 0.1, 9: 0.2, 10: 0.1}, 'low_delta': {1: 0.2, 2: 0.1, 3: 0.1, 4: 0.1, 5: 0.1, 6: 0.1, 7: 0.1, 8: 0.1, 9: 0.1, 10: 0.4}, 'p_hat': {1: 0.2, 2: 0.1, 3: 0.3, 4: 0.3, 5: 0.1, 6: 0.3, 7: 0.2, 8: 0.2, 9: 0.1, 10: 0.8}} df = pandas.DataFrame(d) df['p_hat'].plot(yerr=df[['low_delta', 'high_delta']].T.values) (df.p_hat + df.high_delta).plot(style='.') (df.p_hat - df.low_delta).plot(style='*') 

The lower bounds always seem to match what I would expect, but instead of adding values ​​on the upper bound, the lower bound seems to be adding values ​​again.

How should errors be passed to matplotlib so that error strings display correctly?

+6
source share
1 answer

Short answer: use 1x2xN 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 an error in Pandas that causes Pandas to interpret the error strings specified in the 2xN form for the series in the same way that it interprets several error bars for multiple rows of the DataFrame. Since you, obviously, draw only 1 line / row, only the first element of the list of error bars is used and is interpreted as symmetrical errors.

Until the error is fixed in Pandas, you can β€œtrick” Pandas into using asymmetric error bars by passing errors in the form of Mx2xN, as well as the expected form for asymmetric error bars on DataFrames. To be precise, you need to use a 1x2xN list, which you can simply create by calling f.ex. yerr=[ ... ]

+6
source

Source: https://habr.com/ru/post/977865/


All Articles