Open oldoc63 opened 1 year ago
We can create subplots using .subplot(). The command plt.subplot() needs three arguments to be passed into it:
For instance, the command plt.subplot(2,3,4) would create "Subplot 4" from the figure above.
Any plt.plot() that comes after plt.subplot() will create a line plot in the specified subplot. For instance:
Sometimes, when we are putting multiple subplots together, some elements can overlap and make the figure unreadable. We can customize the spacing between our subplots to make sure that the figure we create is visible and easy to understand. To do this, we use the plt.subplots_adjust() command. subplots_adjust() has some keyword arguments that can move your plots within the figure:
For example, if we were adding space to the bottom of a graph by changing the bottom margin to 0.2 (instead of the default of 0.1), we would use the command: plt.subplots_adjust(bottom=0.2)
We can also use multiple keyword arguments, if we need to adjust multiple margins. For instance, we could adjust both the top and the hspace: plt.subplots_adjust(top=0.95, hspace=0.25)
Sometimes, we want to display two lines side-by-side, rather than in the same set of x- and y-axes. When we have multiple axes in the same picture, we call each set of axes a subplot. The picture or object that contains all of the subplots is called a figure.
We can have many different subplots in the same figure, and we can lay them out in many different ways. We can think of our layouts as having rows and columns of subplots. For instance, the following figure has six subplots split into 2 rows and 3 columns:
https://content.codecademy.com/courses/matplotlib/six_subplots.svg