]> git.friedersdorff.com Git - max/plotting_with_matplotlib.git/blob - error_bars.py
feat: Add final content
[max/plotting_with_matplotlib.git] / error_bars.py
1 import numpy as np
2 import matplotlib.pyplot as plt
3
4 # example data
5 x = np.arange(0.1, 4, 0.5)
6 y = np.exp(-x)
7
8 # example error bar values that vary with x-position
9 error = 0.1 + 0.2 * x
10
11 fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)
12 ax0.errorbar(x, y, yerr=error, fmt='-o')
13 ax0.set_title('variable, symmetric error')
14
15 # error bar values w/ different -/+ errors that
16 # also vary with the x-position
17 lower_error = 0.4 * error
18 upper_error = error
19 asymmetric_error = [lower_error, upper_error]
20
21 ax1.errorbar(x, y, xerr=asymmetric_error, fmt='o')
22 ax1.set_title('variable, asymmetric error')
23 ax1.set_yscale('log')
24 plt.show()