
上QQ阅读APP看书,第一时间看更新
How it works...
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 plots, because 211 means the first plot in the 2 x 1 grid, which will start in the first row! If we want to draw the same three plots, but arrange two in the first column and one in the second column, as opposed to the current first two in the first row, and the third one in the second row, then we will have to specify a plot sequence of 221, 223, and 122. Try this out as an exercise!