我有像这样的Pandas(version 0.14.1)DataFrame对象

import pandas as pd

df = pd.DataFrame(zip([1,   2,   3,   4,   5],
                      [0.1, 0.3, 0.1, 0.2, 0.4]),
                  columns=['y', 'dy'])
它返回
    y   dy
0   1   0.1
1   2   0.3
2   3   0.1
3   4   0.2
4   5   0.4
其中第一列是值,第二列是错误。
第一种情况:我想为y -values作图
df['y'].plot(style="ro-")
python - 带有错误栏的 Pandas 图: style does not apply-LMLPHP

第二种情况:我想为dy -values添加垂直错误栏y
df['y'].plot(style="ro-", yerr=df['dy'])
python - 带有错误栏的 Pandas 图: style does not apply-LMLPHP

因此,如果我在yerr方法中添加xerrplot参数,它将忽略style
是 Pandas 功能还是错误?

最佳答案

正如TomAugspurger所指出的,它是known issue。但是,在大多数情况下,它有一个简单的解决方法:使用fmt关键字而不是style关键字来指定快捷方式样式选项。

import pandas as pd

df = pd.DataFrame(zip([1,   2,   3,   4,   5],
                      [0.1, 0.3, 0.1, 0.2, 0.4]),
                  columns=['y', 'dy'])

df['y'].plot(fmt='ro-', yerr=df['dy'], grid='on')

python - 带有错误栏的 Pandas 图: style does not apply-LMLPHP

关于python - 带有错误栏的 Pandas 图: style does not apply,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25709985/

10-14 19:02
查看更多