我有像这样的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-")
第二种情况:我想为
dy
-values添加垂直错误栏y
df['y'].plot(style="ro-", yerr=df['dy'])
因此,如果我在
yerr
方法中添加xerr
或plot
参数,它将忽略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,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25709985/