Matplotlib: Asymetric error bar for one bar in bar plot
I want to plot 2 values in a bar plot. The second value shall have an asymetric error bar. What am I doing wrong?
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]])
Edit: The result I get is, that both bars get an yerror (left one min and right one max). Instead I want an asymetric one only for the right bar (min and max of the simulated values).
You could do this by setting yerr like follows:
plt.bar(x_pos, y, yerr=[[0, 0-err_min], [0, err_max]])