Table of Contents

Matplotlib

With matplotlib one can easily create professional graphs and plots using numpy, scipy or pandas data.

Only brief overview here, many nice examples in: http://scipy-cookbook.readthedocs.org/items/idx_matplotlib_simple_plotting.html

matplotlib can be used both for

When working in Jupyter one usually shows the graphs directly in the notebook:

Or one uses separate graphics window:

More recently the package ipympl was introduced which provides additional interactive functionality for inline graphs in notebooks

Simple line-plot example

Storing figures

Adjusting the plot:

Labels, Titles and Legend

colors and line-styles

explicit axis limits

Scatter plots

For simple cases one can just use plt.plot with key o :

More sophisticated plots with plt.scatter

$\rightarrow$ visualize 3rd and 4th dimension

Plotting error-bars

Scientific data, in particular in physics, often has errors associated to the y-coordinate (sometimes also to x)

Histograms

Fundamental plot type to visualize data distributions, mostly in 1D but also 2D or even 3D

Some more options for Histograms

Many options how to fill and display histograms

2d histograms

2 variables can of course be plotted as x-y point plot:

But often more instructive to use 2D histo

Interactive Plots

Using interact from ipywidgets package one can create graphs with interactive control

Other features

Of course there are many more features in matplotlib, such as

We will see some of that in the following chapters.