1 Plotting with Matplotlib
2 ------------------------
4 Also creating a presentation with rst2pdf
5 =========================================
9 Favour simpler data structures if they do what you need. In order:
13 - Can't install system dependencies
15 - 2 (or higher) dimensional data
16 - Lots of numerical calculations
17 #. Pandas series/dataframes
18 - 'Data Wrangling', reshaping, merging, sorting, querying
19 - Importing from complex formats
21 Shamelessly stolen from https://stackoverflow.com/a/45288000
23 Loading Data from Disk
24 ----------------------
28 .. code-block:: python
31 >>> with open('eggs.csv', newline='') as csvfile:
32 ... spam = csv.reader(csvfile,
39 Loading Data from Disk
40 ----------------------
44 .. code-block:: python
47 >>> spam = numpy.genfromtxt('eggs.csv',
49 ... dtype=None) # No error handling!
54 ``numpy.genfromtxt`` will try to infer the datatype of each column if
55 ``dtype=None`` is set.
57 ``numpy.loadtxt`` is generally faster at runtime if your data is well formated
58 (no missing values, only numerical data or constant length strings)
60 Loading Data from Disk
61 ----------------------
65 .. code-block:: python
68 >>> # dtype=None is def
69 >>> spam = pandas.read_csv('eggs.csv',
76 ``header=None`` is required if the flie does not have a header.
80 Generating Data for Testing
81 ---------------------------
83 Generating the data on the fly with numpy is convenient.
85 .. code-block:: python
87 >>> import numpy.random as ran
88 >>> # For repeatability
90 >>> # Uniform [0, 1) floats
91 >>> data = ran.rand(100, 2)
92 >>> # Uniform [0, 1) floats
93 >>> data = ran.rand(100, 100, 100)
94 >>> # Std. normal floats
95 >>> data = ran.randn(100)
96 >>> # 3x14x15 array of binomial ints with n = 100, p = 0.1
97 >>> data = ran.binomial(100, 0.1, (3, 14, 15))
102 Plot data of the form:
106 .. code-block:: python
108 >>> import matplotlib.pyplot as plt
111 >>> x = (ran.rand(50)*50) + 2000 # I don't have real data
113 >>> plt.title('Some time series with left title', loc='left')
114 >>> plt.ylabel('Mass of test mass over time')
120 .. code-block:: python
122 :end-at: ax.set_xlabel('XLabel0')
124 .. code-block:: python
126 :start-at: for i in range(3):