From 63dccc1b9aa48de53fdf8b2af0d1e6d30097c696 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Wed, 30 Jan 2019 22:40:26 +0000 Subject: [PATCH] feat: Add final content --- error_bars.py | 24 ++++++++++++++++++++++++ slides.rst | 29 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 error_bars.py diff --git a/error_bars.py b/error_bars.py new file mode 100644 index 0000000..4fbe21c --- /dev/null +++ b/error_bars.py @@ -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() diff --git a/slides.rst b/slides.rst index 79c4685..d15eab4 100644 --- a/slides.rst +++ b/slides.rst @@ -57,6 +57,20 @@ Numpy ``numpy.loadtxt`` is generally faster at runtime if your data is well formated (no missing values, only numerical data or constant length strings) +Loading Data from Disk +---------------------- +Numpy NB. +========= +**Remind me to look at some actual numpy usage at the end** + +- I think numpy does some type coercion when creating arrays. +- Arrays created by ``numpy.genfromtxt`` can not in general be indexed like + ``data[xstart:xend, ystart:yend]``. +- Data of unequal types are problematic! Pandas *may* be a better choice in + that case. +- Specifying some value for ``dtype`` is probably necessary in most cases in + practice: https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html + Loading Data from Disk ---------------------- Pandas @@ -130,8 +144,23 @@ The keyword arguments are optional here. Other options exist. Error Bars ---------- +.. code-block:: python + :include: error_bars.py + Stacked Bar Graph ----------------- .. code-block:: python :include: stacked_bars.py + +Resources +--------- +NumPy User Guide: https://docs.scipy.org/doc/numpy/user/index.html + +NumPy Reference: https://docs.scipy.org/doc/numpy/reference/index.html#reference + +Matplotlib example gallery: https://matplotlib.org/gallery/index.html + +Pandas: It probably exists. Good luck. + +This presentation: https://git.friedersdorff.com/max/plotting_with_matplotlib.git -- 2.44.0