]> git.friedersdorff.com Git - max/plotting_with_matplotlib.git/blobdiff - error_bars.py
feat: Add final content
[max/plotting_with_matplotlib.git] / error_bars.py
diff --git a/error_bars.py b/error_bars.py
new file mode 100644 (file)
index 0000000..4fbe21c
--- /dev/null
@@ -0,0 +1,24 @@
+import numpy as np
+import matplotlib.pyplot as plt
+
+# example data
+x = np.arange(0.1, 4, 0.5)
+y = np.exp(-x)
+
+# example error bar values that vary with x-position
+error = 0.1 + 0.2 * x
+
+fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)
+ax0.errorbar(x, y, yerr=error, fmt='-o')
+ax0.set_title('variable, symmetric error')
+
+# error bar values w/ different -/+ errors that
+# also vary with the x-position
+lower_error = 0.4 * error
+upper_error = error
+asymmetric_error = [lower_error, upper_error]
+
+ax1.errorbar(x, y, xerr=asymmetric_error, fmt='o')
+ax1.set_title('variable, asymmetric error')
+ax1.set_yscale('log')
+plt.show()