Subplots
In the previous section, we have seen a couple of important functions without introducing them. Let's have a look at them now:
fig = plt.figure():
This function returns aFigure
, where we can add one or moreAxes
instances.ax = fig.add_subplot(111):
This function returns anAxes
instance, where we can plot (as done so far), and this is also the reason why we call the variable referring to that instanceax
(fromAxes)
. This is a common way to add anAxes
to aFigure
, butadd_subplot()
does a bit more: it adds a subplot. So far we have only seen aFigure
with oneAxes
instance, so only one area where we can draw, but Matplotlib allows more than one.
add_subplot()
takes three parameters:
fig.add_subplot(numrows, numcols, fignum)
where:
numrows
represents the number of rows of subplots to preparenumcols
represents the number of columns of subplots to preparefignum
varies from1
tonumrows*numcols
and specifies the current subplot (the one used now)
Basically, we describe a matrix...