更改capplotlib中的错误栏的样式 [英] Change capstyle for errorbars in matplotlib
问题描述
我想将错误栏垂直线的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个对象. plotline
和cap
是Line2D
对象,然后可以执行以下操作:
plt.errorbar
returns 3 objects. plotline
and cap
are Line2D
objects, which you can then do:
plotline.set_capstyle('round')
cap.set_capstyle('round')
barlinecols
是LineCollection
对象.但是,当前版本(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屋!