1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| import numpy as np import matplotlib.pyplot as plt
x = np.array([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]) y = np.exp(-x) xerr = 0.1 yerr = 0.2
lolims = np.array([0, 0, 1, 0, 1, 0, 0, 0, 1, 0], dtype=bool) uplims = np.array([0, 1, 0, 0, 0, 1, 0, 0, 0, 1], dtype=bool) ls = 'dotted'
fig, ax = plt.subplots(figsize=(7, 4))
ax.errorbar(x, y, xerr=xerr, yerr=yerr, linestyle=ls)
ax.errorbar(x, y + 0.5, xerr=xerr, yerr=yerr, uplims=uplims, linestyle=ls)
ax.errorbar(x, y + 1.0, xerr=xerr, yerr=yerr, lolims=lolims, linestyle=ls)
ax.errorbar(x, y + 1.5, xerr=xerr, yerr=yerr, lolims=lolims, uplims=uplims, marker='o', markersize=8, linestyle=ls)
xerr = 0.2 yerr = np.zeros_like(x) + 0.2 yerr[[3, 6]] = 0.3
xlolims = lolims xuplims = uplims lolims = np.zeros(x.shape) uplims = np.zeros(x.shape) lolims[[6]] = True uplims[[3]] = True
ax.errorbar(x, y + 2.1, xerr=xerr, yerr=yerr, xlolims=xlolims, xuplims=xuplims, uplims=uplims, lolims=lolims, marker='o', markersize=8, linestyle='none')
ax.set_xlim((0, 5.5)) ax.set_title('Errorbar upper and lower limits') plt.show()
|