我正在尝试使用pandas和matplotlib绘制一系列带有不对称误差条的图。以下是代码:
下限总是符合我的预期,但它似乎不是在上限上添加值,而是再次添加下限的值。如何将错误传递给matplotlib,以便误差条正确呈现?
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='*')
下限总是符合我的预期,但它似乎不是在上限上添加值,而是再次添加下限的值。如何将错误传递给matplotlib,以便误差条正确呈现?
plt.errorbar(df.index.values, df['p_hat'].values, yerr=df[['low_delta', 'high_delta']].T.values)
替换df['p_hat'].plot()
,一切都正常工作,但我想让它在pandas中工作,或者至少知道为什么不行。 - 2daaa