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 moreAxesinstances.ax = fig.add_subplot(111):This function returns anAxesinstance, 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 anAxesto aFigure, butadd_subplot()does a bit more: it adds a subplot. So far we have only seen aFigurewith oneAxesinstance, 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:
numrowsrepresents the number of rows of subplots to preparenumcolsrepresents the number of columns of subplots to preparefignumvaries from1tonumrows*numcolsand specifies the current subplot (the one used now)
Basically, we describe a matrix...