python - 更改 matplotlib 中错误栏的 capstyle

标签 python matplotlib errorbar

我想将错误栏垂直线的标题样式设置为“圆形”。例如,以下代码生成一些带有误差条的点:

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 中设置上限样式:

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

我还发现了一些很好的例子,如何获得刻度的圆形标题:

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

但我无法找到类似的错误栏方法。

最佳答案

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 对象,您可以执行以下操作:

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

barlinecols 是一个 LineCollection 对象。但是,当前版本 (matplotlib 2.0) 不支持更改 LineCollection 对象中的 capstyle(请参阅: https://github.com/matplotlib/matplotlib/issues/8277 )。不过看起来这会在下一个版本中实现。

关于python - 更改 matplotlib 中错误栏的 capstyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40292875/

相关文章:

python - Matplotlib 强制虚线接触轴

r - 如何在ggplot中绘制虚线95%置信区间

python - PyQt5,多种颜色的Qlabel文本

python - 有没有办法将列表作为 argparse 中的参数之一传递

python - Matplotlib:用鼠标画出矩形形状的选区

python - 按类别分隔的 Pandas 数据框误差条图

r - ggplot 使用第二个数据源作为错误栏失败

python - Tkinter 标签更新问题

python - 在美国的 basemap 中为多边形添加颜色条

python - 图例在 matplotlib 中使用 PathCollections