pandas 图中错误栏的样式 [英] Style of error bar in pandas plot

查看:55
本文介绍了 pandas 图中错误栏的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用以下样式绘制带有错误栏的折线图.

I'd like to plot line chart with error bar with the following style.

但是,熊猫图只用垂直线绘制误差线.

However, pandas plot draws error bars with only vertical line.

pd.DataFrame([1,2,3]).plot(yerr=[0.3,.3,.3])

如何更改熊猫图的误差线样式?

How do I change style of error bar for pandas plot?

版本为:

  • pandas'0.18.0'
  • matplotlib'1.5.1'

一个原因似乎是使用了seaborn风格.下面的代码给出了漂亮的样式图.

One of the reason seems using the seaborn style. The following code give the nice style plot.

# plt.style.use('seaborn-paper')
pd.DataFrame([1,2,3]).plot(yerr=[0.3,.3,.3],capsize=4)

但是,我有理由继续使用淡淡的风格...请帮忙.

But, I have a reason to keep using seaborn style... Please help.

推荐答案

当您在DataFrame上调用plot时,可以使用capsize kwarg(将其传递给 plt.errorbar ):

You can change the capsize inline when you call plot on your DataFrame, using the capsize kwarg (which gets passed on to plt.errorbar):

pd.DataFrame([1,2,3]).plot(yerr=[0.3,.3,.3],capsize=4)


或者,您可以使用 rcParams 更改此设置.


Alternatively, you can change this setting using rcParams

您可以通过打印plt.rcParams['errorbar.capsize']来查找默认的错误栏上限大小.如果该值为0(这就是我怀疑您目前没有错误栏上限的原因),则可以使用以下方法将错误栏上限的默认大小设置为非零值:

You can find out what your default errorbar cap size is by printing plt.rcParams['errorbar.capsize']. If that is 0 (which is why I suspect you are currently getting no errorbar caps), you can set the default size of the errorbar caps to something nonzero, using:

plt.rcParams['errorbar.capsize']=4

请确保在任何绘图脚本的开头都有该内容.

Make sure to have that at the beginning of any plotting script.

似乎使用seaborn-paper样式将瓶盖厚度设置为0.您可以使用capthick kwarg覆盖它:

It seems using the seaborn-paper style sets the cap thickness to 0. You can override this with the capthick kwarg:

plt.style.use('seaborn-paper')
pd.DataFrame([1,2,3]).plot(yerr=[0.3,.3,.3],capsize=4,capthick=1)

这篇关于 pandas 图中错误栏的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆