Matplotlib:条形图中一个条形的不对称误差条
Matplotlib: Asymetric error bar for one bar in bar plot
我想在条形图中绘制 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]])
编辑: 我得到的结果是,两个条形图都出现错误(左边一分钟,右边一分钟)。相反,我只想要一个不对称的右栏(模拟值的最小值和最大值)。
您可以通过如下设置 yerr 来做到这一点:
plt.bar(x_pos, y, yerr=[[0, 0-err_min], [0, err_max]])
我想在条形图中绘制 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]])
编辑: 我得到的结果是,两个条形图都出现错误(左边一分钟,右边一分钟)。相反,我只想要一个不对称的右栏(模拟值的最小值和最大值)。
您可以通过如下设置 yerr 来做到这一点:
plt.bar(x_pos, y, yerr=[[0, 0-err_min], [0, err_max]])