【问题标题】:matplotlib bar method not returning error barsmatplotlib bar 方法不返回错误栏
【发布时间】:2021-05-04 19:45:12
【问题描述】:

根据 matplotlib 文档,方法 matplotlib.pyplot.bar() 返回一个

“包含所有条形图和可选误差线的容器”

(https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html)

我用以下代码创建了一个条形图:

x = plt.bar(spacing, medians, yerr=yerr, capsize=20, width=0.5, tick_label = x_labels, edgecolor= "black")

创建以下条形图:

但是,变量 x 仅包含条形图,而不是文档中所说的误差线。

有什么方法可以查看错误栏吗?

【问题讨论】:

    标签: python matplotlib errorbar


    【解决方案1】:

    您应该能够使用以下方式访问它们:

    x.errorbar.get_children()
    

    要获取线段,可以在LineCollection上使用get_segments()

    x.errorbar.get_children()[0].get_segments()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 2011-09-10
      • 2021-03-30
      • 1970-01-01
      相关资源
      最近更新 更多