Pandas plot with errorbar:样式不适用

2024-04-18 00:37:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有Pandas(版本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'])

它回来了

^{pr2}$

其中第一列是,第二列是error。在

第一个案例:我想为y-值绘制一个图

df['y'].plot(style="ro-")

First case

第二种情况:我想为y-值添加一个垂直错误条dy

df['y'].plot(style="ro-", yerr=df['dy'])

Second case

所以,如果我将yerrxerr参数添加到plot方法中,它将忽略style。在

是熊猫的特征还是虫子?在


Tags: 对象import版本dataframepandasdfroplot
1条回答
网友
1楼 · 发布于 2024-04-18 00:37:15

正如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')

correctly styled figure

相关问题 更多 >

    热门问题