【问题标题】:Matplotlib: Asymetric error bar for one bar in bar plotMatplotlib:条形图中一个条形的不对称误差条
【发布时间】:2022-01-18 13:25:07
【问题描述】:

我想在条形图中绘制 2 个值。第二个值应具有不对称误差条。我做错了什么?

from matplotlib import pyplot as plt
import numpy as np

observed = 23
simulated = [18, 21, 25, 27, 20.5]
diff = [(x - np.mean(simulated)) for x in simulated]

y = [observed, np.mean(simulated)]
err_min = np.min(diff)
err_max = np.max(diff)

x_pos = [i for i, _ in enumerate(y)]

plt.bar(x_pos, y, yerr=[[0, 0], [err_min, err_max]])

编辑: 我得到的结果是,两个条形图都有一个 yerror(左一分钟,右一最大)。相反,我只想要一个不对称的条形图(模拟值的最小值和最大值)。

【问题讨论】:

  • 你能分享任何错误信息吗?
  • 请参阅documentationshape(2, N): Separate - and + values for each bar. First row contains the lower errors, the second row contains the upper errors. 此外,这些值应该 >= 0,而不是负数。

标签: python numpy matplotlib errorbar


【解决方案1】:

你可以通过如下设置 yerr 来做到这一点:

    plt.bar(x_pos, y, yerr=[[0, 0-err_min], [0, err_max]])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 2018-08-22
    • 2017-03-27
    • 1970-01-01
    • 2018-11-29
    相关资源
    最近更新 更多