Layouts
There are multiple ways to define a visualization layout in Matplotlib. By layout, we mean the arrangement of multiple Axes within a Figure. We will start with subplots and how to use the tight layout to create visually appealing plots and then cover GridSpec, which offers a more flexible way to create multi-plots.
Subplots
It is often useful to display several plots next to one another. Matplotlib offers the concept of subplots, which are multiple Axes within a Figure. These plots can be grids of plots, nested plots, and so on.
Explore the following options to create subplots:
- The
plt.subplots(, ncols)
function creates a Figure and a set of subplots.nrows, ncols
define the number of rows and columns of the subplots, respectively. - The
plt.subplot(nrows, ncols, index)
function or, equivalently,plt.subplot(pos)
adds a subplot to the current Figure. The index starts at 1. Theplt.subplot(2, 2, 1)
function is equivalent toplt.subplot(221)
. - The
Figure...