Matplotlib 3.0 Cookbook
上QQ阅读APP看书,第一时间看更新

Getting ready

We will use the same Wine Quality and Iris datasets that were introduced in Chapter 2Getting Started with Basic Plots, for the examples in this chapter. 

Multiple plots in the figure are arranged in an m x n grid, where m is the number of rows, and n is the number of columns. If we have six plots to be arranged in the figure, we can either arrange all of them in one row (each of them is identified by 161, 162, 163, 164, 165, or 166) or 3 x 2 (321, 322, 323, 324, 325, and 326) or 2 x 3 (231, 232, 233, 234, 235, and 236) or one column (611, 612, 613, 614, 615, and 616). The first two digits represent the number of rows and columns, and the last digit represents the sequential numbers 1 to 6 (total number of plots), and reads from left to right,and then from the top down.

The plots can also be specified as (3, 2, 1) instead of (321). When there are more than nine plots in the grid, the later notation is confusing, and Matplotlib does not accept it. In such cases, we must use (3, 4, 10), (3, 4, 11), or (3, 4, 12) instead of (3410), (3411), or (3412), when you have a 3 x 4 grid with a total of 12 plots.

We can also plot fewer plots than the maximum allowed in the grid, for example, three plots in a 2 x 2 grid (four is the maximum).

Import the required libraries:

import pandas as pd
import matplotlib.pyplot as plt