Lesson 4 ❮ Lesson List ❮ Top Page
❯ 4.1 Intro to matplotlib
4.5 Multiple Plots with Seaborn
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳ Video 8m 18s
☷ Interactive readings 5m
With matplotlib, we use the following import convention:
import matplotlib.pyplot as plt
The subplots method of matplotlib can be used to make multiple plot.
This method returns two variables for the figure and the axis, usually named fig and ax.
Common options in subplots:
nrows, ncols
Number of rows/columns of the subplot grid.
sharex, sharey
Controls sharing of properties among x (sharex) or y (sharey) axes.
Matplotlib's main plot function accepts arrays of x and y coordinates and optionally a string abbreviation indicating color and line style. For example, to plot x versus y with green dashes, you would execute:
ax.plot(x, y, 'g--')
The same plot could also have been expressed more explicitly as:
ax.plot(x, y, linestyle='--', color='g')
Line styles help differentiate the graphs. Here are the character representing the linestyle:
Color is another way to differentiate line graphs. The following list shows the color
Markers add a special symbol to each data point in a line graph. The following list shows some of the markers:
Sometimes we want to format the number of ticks and the labels.
To change the axis ticks, we can use set_xticks, set_yticks.
For changing the name of the ticks, we can use set_xticklabels, set_yticklabels.
Lastly, using the method suptitle on the fig and set_title on the ax, we can give the title to our figures.