

To display the figure, we use the show() function.Then, we use the tight_layout() function to auto-adjust the layout of multiple plots.After this, we create multiple plots individually using the subplot() function.Then, we create a figure using the figure() function.Firstly, we import matplotlib.pyplot library for creating plots.In this example, we’ll use the subplot() function to create multiple plots. Here we’ll see an example of multiple plots using matplotlib functions subplot() and subplots(). On the other hand, the subplot() function only constructs a single subplot ax at a given grid position.Īlso, check Matplotlib subplots_adjust Matplotlib multiple plots example
#Matplotlib add subplot to existing figure code#
While using the subplots() function you can use just one line of code to produce a figure with multiple plots. gridspec_kw: It is used to create the grid on which multiple plots are located.subplot_kw: The dict with keywords provided to the add subplot method, which is used to create each subplot.


Multiple pots are made and arranged in a row from the top left in a figure. Matplotlib’s subplot() and subplots() functions facilitate the creation of a grid of multiple plots within a single figure.
