Here is the explanation for the code:
- plt.figure() creates the object for the figure and allocates space for it.
- plt.subplot(221) creates the axes for the first plot in a 2 x 2 grid.
- plt.subplot(222) creates one more axis for the second plot in a 2 x 2 grid, which is placed in the same first row.
- plt.subplot(212) creates one more axes for the third plot, but this is part of another 2 x 1 grid (the first two digits of 212) and it is the second plot in this 2 x 1 grid, so it will be placed in the second row. Since the first 2 x 2 grid did not use the second row, this grid will occupy the full space.
We get the output as follows:
If we had coded plt.subplot(211) for the third plot, it would have overwritten the first two ...