]> git.friedersdorff.com Git - max/plotting_with_matplotlib.git/commitdiff
Starting a presentation on plotting with matplotlib
authorMaximilian Friedersdorff <max@friedersdorff.com>
Thu, 24 Jan 2019 17:03:36 +0000 (17:03 +0000)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Thu, 24 Jan 2019 17:03:36 +0000 (17:03 +0000)
.gitignore [new file with mode: 0644]
dark.png [new file with mode: 0644]
dark.style [new file with mode: 0644]
slides.rst [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..bbf52ab
--- /dev/null
@@ -0,0 +1 @@
+slides.pdf
diff --git a/dark.png b/dark.png
new file mode 100644 (file)
index 0000000..f76e81a
Binary files /dev/null and b/dark.png differ
diff --git a/dark.style b/dark.style
new file mode 100644 (file)
index 0000000..deaaad9
--- /dev/null
@@ -0,0 +1,86 @@
+pageSetup:
+    size: null
+    width: 16cm
+    height: 9cm
+    margin-top: 0cm
+    margin-bottom: 0cm
+    margin-left: 0cm
+    margin-right: 0cm
+    margin-gutter: 0cm
+    spacing-header: 2mm
+    spacing-footer: 2mm
+    firstTemplate: standardPage
+
+pageTemplates:
+    standardPage:
+        frames: []
+            [3%, 3%, 94%, 94%]
+        showHeader: false
+        showFooter: false
+        background: dark.png
+
+linkColor: #add8e6
+
+styles:
+    normal:
+        fontSize: 10
+        textColor: white
+
+    bodytext:
+        alignment: TA_LEFT
+        hyphenation: false
+        spaceBefore: 3
+
+    titleslideinfo:
+        parent: normal
+        alignment: TA_CENTER
+
+    literal:
+        textColor: silver
+
+    table:
+      commands: []
+             [ROWBACKGROUNDS, [0, 0], [-1, -1], [#333333, black]]
+
+    table-heading:
+      parent: heading
+      backColor: black 
+      alignment : TA_LEFT
+
+    code:
+        parent: literal
+        fontSize: 11
+        leftIndent: 0
+        spaceBefore: 8
+        spaceAfter: 8
+        backColor: #333333
+
+    bullet-list: 
+      spaceBefore: 0
+      spaceAfter: 0
+      commands: []
+                [VALIGN, [0, 0], [-1, -1], TOP]
+                [TOPPADDING, [0, 0], [-1, -1], 0]
+                [BOTTOMPADDING, [0, 0], [-1, -1], 0]
+
+    endnote:
+        spaceBefore: 0
+        spaceAfter: 0
+        colWidths: [3cm, null]
+
+    field-list: 
+      spaceBefore: 0
+      spaceAfter: 0
+
+    item-list: 
+      spaceBefore: 0
+      spaceAfter: 6
+      commands: []
+                [VALIGN, [0, 0], [-1, -1], TOP]
+                [TOPPADDING, [0, 0], [-1, -1], 5]
+                [BOTTOMPADDING, [0, 0], [-1, -1], 20]
+                [RIGHTPADDING, [0, 0], [1, -1], 0]
+
+    option-list: 
+      spaceBefore: 0
+      spaceAfter: 0
diff --git a/slides.rst b/slides.rst
new file mode 100644 (file)
index 0000000..e6ff018
--- /dev/null
@@ -0,0 +1,115 @@
+Plotting with Matplotlib
+------------------------
+
+Also creating a presentation with rst2pdf
+=========================================
+
+Data Structures
+---------------
+Favour simpler data structures if they do what you need.  In order:
+
+#. Built-in Lists
+    - 2xN data or simpler
+    - Can't install system dependencies
+#. Numpy arrays
+    - 2 (or higher) dimensional data
+    - Lots of numerical calculations
+#. Pandas series/dataframes
+    - 'Data Wrangling', reshaping, merging, sorting, querying
+    - Importing from complex formats
+
+Shamelessly stolen from https://stackoverflow.com/a/45288000
+
+Loading Data from Disk
+----------------------
+Natively
+========
+
+.. code-block:: python
+
+   >>> import csv
+   >>> with open('eggs.csv', newline='') as csvfile:
+   ...     spam = csv.reader(csvfile, 
+   ...                       delimiter=' ', 
+   ...                       quotechar='|')
+   ...     for row in spam:
+   ...         # Do things
+   ...         pass
+
+Loading Data from Disk
+----------------------
+Numpy
+=====
+
+.. code-block:: python
+
+   >>> import numpy
+   >>> spam = numpy.genfromtxt('eggs.csv', 
+   ...                         delimiter=' ', 
+   ...                         dtype=None) # No error handling!
+   >>> for row in spam:
+   ...     # Do things
+   ...     pass
+
+``numpy.genfromtxt`` will try to infer the datatype of each column if 
+``dtype=None`` is set.
+
+``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
+----------------------
+Pandas
+======
+
+.. code-block:: python
+
+   >>> import pandas
+   >>> # dtype=None is def
+   >>> spam = pandas.read_csv('eggs.csv',
+   ...                        delimiter=' ',
+   ...                        header=None) 
+   >>> for row in spam:
+   ...     # Do things
+   ...     pass
+
+``header=None`` is required if the flie does not have a header.
+
+
+
+Generating Data for Testing
+---------------------------
+
+Generating the data on the fly with numpy is convenient.
+
+.. code-block:: python
+
+   >>> import numpy.random as ran
+   >>> # For repeatability 
+   >>> ran.seed(7890234) 
+   >>> # Uniform [0, 1) floats
+   >>> data = ran.rand(100, 2)
+   >>> # Uniform [0, 1) floats
+   >>> data = ran.rand(100, 100, 100)
+   >>> # Std. normal floats
+   >>> data = ran.randn(100)
+   >>> # 3x14x15 array of binomial ints with n = 100, p = 0.1
+   >>> data = ran.binomial(100, 0.1, (3, 14, 15))
+
+Plotting Time Series
+--------------------
+
+Plot data of the form:
+
+.. math:: y=f(t)
+
+.. code-block:: python
+
+   >>> import matplotlib.pyplot as plt
+   >>>
+   >>> t = range(50)
+   >>> x = (ran.rand(50)*50) + 2000 # I don't have real data
+   >>> plt.plot(t, x)
+   >>> plt.title('Some time series with left title', loc='left')
+   >>> plt.ylabel('Mass of test mass over time')
+   >>> plt.show()