我想在条形图中绘制两个值。第二个值应具有不对称误差条。我做错了什么?
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]])
编辑:我得到的结果是,两个小节都得到一个yeror(左一分钟,右一分钟(。相反,我想要一个只适用于右栏(模拟值的最小值和最大值(的非对称的。
您可以通过如下设置yerr来实现这一点:
plt.bar(x_pos, y, yerr=[[0, 0-err_min], [0, err_max]])