更改capplotlib中的错误栏的样式 [英] Change capstyle for errorbars in matplotlib

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

问题描述

我想将错误栏垂直线的capstyle设置为'round'.例如,以下代码产生一些带有错误栏的点:

I would like to set the capstyle for the vertical lines of an error bar to 'round'. For example, the following code produces some points with errorbars:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
plt.plot([1,2,3], [2,3,4], marker='o', linestyle='None')
plt.errorbar([1,2,3], [2,3,4], yerr=[1,1,1], fmt=None, linewidth=3, capsize=0)
plt.xlim([0,4])
plt.show()

对于普通线条,我可以使用以下方法在rcParams中设置大写字母样式:

For normal lines, I can set the cap style in the rcParams using this:

plt.rcParams['lines.dash_capstyle'] = 'round'

我还找到了一些不错的示例,如何获取刻度线的圆角样式:

and I also found some nice examples how to get round capstyles for ticks:

for i in ax.xaxis.get_ticklines(): i._marker._capstyle = 'round'

但是我找不到错误栏的类似方法.

but I am not able to find a similar way for the errorbars.

推荐答案

plotline, cap, barlinecols =\
         plt.errorbar([1,2,3], [2,3,4], yerr=[1,1,1], fmt=None, linewidth=3, capsize=0)

plt.errorbar返回3个对象. plotlinecapLine2D对象,然后可以执行以下操作:

plt.errorbar returns 3 objects. plotline and cap are Line2D objects, which you can then do:

plotline.set_capstyle('round')
cap.set_capstyle('round')

barlinecolsLineCollection对象.但是,当前版本(matplotlib 2.0)不支持在LineCollection对象中更改capstyle(请参阅:

barlinecols is a LineCollection object. However, the current version (matplotlib 2.0) does not support changing capstyle in LineCollection objects (see: https://github.com/matplotlib/matplotlib/issues/8277). But it looks like this will be implemented in the next version.

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

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