Pandas DataFrame绘图标记

5
有没有办法在pandas.DataFrame.plot中设置标记样式?通过设置kind,所有其他选项都可用。我想要一个带有误差棒的标记,但只得到了带有误差棒的线条。如果我通过errorbar函数来实现这一点,我会设置fmt='.'。

2
抱歉,我发布了一个答案,但是又删除了它。你需要的是 df.plot(style='.') 吗? - EdChum
2个回答

5

这个问题并没有具体说明,但要看你是要绘制数据框还是系列。

绘制数据框

可以重复使用@unutbu的示例:

from numpy import arange, random
import pandas as pd
df = pd.DataFrame({'x': arange(10), 'y': random.randn(10), 'err': random.randn(10)})
df.plot('x', 'y', yerr='err', fmt='.')

在DataFrame中绘制Series

这次有点不同:

df.y.plot(fmt='.')
AttributeError: Unknown property fmt

您需要:

df.y.plot(style='.')

style与 DataFrame 的行为

如果将 style 传递给 DataFrame.plot,则 "没有发生任何事情":

序列的图形

df.plot('x', 'y', yerr='err', style='.')

使用默认格式绘制的数据帧图

可能不是你想要的。


4

df.plot 会将额外的关键参数传递给底层的 matplotlib 绘图函数。因此,

df = pd.DataFrame({'x':np.arange(10), 'y':np.random.randn(10), 
                   'err':np.random.randn(10)})
df.plot('x', 'y', yerr='err', fmt='.')

收益率 enter image description here

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接