6. Plotting#

We can use Python to produce plots of data and save them to a file. Here we will look at how we can create the most common types of plots.

Line plot

Fig. 6.1 Line plot#

Multiple line plot

Fig. 6.2 Multiple line plot#

Scatter plot

Fig. 6.3 Scatter plot#

Surface plot

Fig. 6.4 Surface plot#

Contour plot

Fig. 6.5 Contour plot#

Image plot

Fig. 6.6 Image plot#


6.1. matplotlib#

matplotlib is a library of functions that allows us to produce plots of data within a Python program. Like with other libraries, we need to import it using the import command. For example, to import the matplotlib module pyplot which is used for the most common plots we use the following code

import matplotlib.pyplot as plt

This will allow us to call pyplot functions using the precursor plt..