pandas DataFrame 绘图标记
pandas DataFrame plot marker
有没有办法在pandas.DataFrame.plot中设置标记样式?所有其他选项都可以通过设置种类来使用。我想要一个带有错误栏的标记,但只得到一行带有错误栏的行。如果我要通过函数 errorbar 执行此操作,我会设置 fmt='.'
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='.')
产量
OP 没有具体说明,但这取决于您是要绘制 Dataframe 还是系列。
绘制数据帧
重用@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 中绘制系列
这次有点不一样:
df.y.plot(fmt='.')
AttributeError: Unknown property fmt
你需要:
df.y.plot(style='.')
具有 style
的 DataFrame 行为
如果将style
传给DataFrame.plot
,"nothing happens":
df.plot('x', 'y', yerr='err', style='.')
这可能不是您想要的。
有没有办法在pandas.DataFrame.plot中设置标记样式?所有其他选项都可以通过设置种类来使用。我想要一个带有错误栏的标记,但只得到一行带有错误栏的行。如果我要通过函数 errorbar 执行此操作,我会设置 fmt='.'
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='.')
产量
OP 没有具体说明,但这取决于您是要绘制 Dataframe 还是系列。
绘制数据帧
重用@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 中绘制系列
这次有点不一样:
df.y.plot(fmt='.')
AttributeError: Unknown property fmt
你需要:
df.y.plot(style='.')
具有 style
的 DataFrame 行为
如果将style
传给DataFrame.plot
,"nothing happens":
df.plot('x', 'y', yerr='err', style='.')
这可能不是您想要的。