April 2018
Beginner to intermediate
300 pages
7h 34m
English
When we need to create a larger number of subplots of the same size, it can be quite inefficient to generate them one by one with the plt.subplot() or fig.add_subplot() function. In this case, we can call plt.subplots() to generate an array of subplots at once.
plt.subplots() takes in the number of rows and columns as input parameters, and returns a Figure together with a grid of subplots stored in a NumPy array. When there is no input parameter, plt.subplots() is equivalent to plt.figure() plus plt.subplot() by default.
Here is a code snippet for demonstration:
import matplotlib.pyplot as pltfig, axarr = plt.subplots(1,1)print(type(fig))print(type(axarr))plt.show()
From the resultant screenshot ...
Read now
Unlock full access