Working With Multiple Subplots
A figure can have more than one subplot. Earlier, you learned that you can obtain your figure and axes objects by calling
plt.subplots() and passing in a figure size. This function can take two additional arguments:
- The number of rows
- The numbers of columns
These arguments determine how many axes objects will belong to the figure, and by extension, how many axes objects will be returned to you. In the following code,
nrows is set to
ncols is set to
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
This function returns two axes objects, which you store in a tuple.
Become a Member to join the conversation.