Matplotlib is a Python library that can be used for plotting graphs and figures.
Plotting multiplots or multiple plots are often required either for comparing the two curves or show some gradual changes in the multiple plots, and this can be done using Subplots. Subplots are one of the most important and fundamental concepts to be understood while trying to plot multiple figures/graphs/plots in the same, and this tutorial shows you how it is done.
matplotlib.pyplot.subplot(nrows, ncols, index)
There are also certain keyword arguments that can be given.
The Stacked Plots
First, let’s try to plot a sequence of plots (3 here) by stacking one over the other. As we are stacking them, it’s the number of rows (nrows) that change, meaning ncols stay the same as 1. Each subplot is identified by the index parameter.
Next, we’ll try to plot some graphs as a grid, that is, multiplots with multiple columns. Here, we will create a multiplot with 4 plots, we will make it a 2×2 grid, which means nrows=2 and ncols=2, with each image being identified by the index again, in a row-major order.
If we were to create a multiplot where one plot overlaps over the other one, kind of like what we see when we minimize a youtube video but it still runs in a small window at the bottom corner, then the
add_suplplot() function helps in this.
Oh, and also, for all the subplot functions that we’ve implemented, if nrows, ncols, and index are less than 10, instead of giving the arguments in the (nrows, ncols, index) format, they can be passed as a three-digit digit in the format
(nrows*100+ncols*10+index), and the output would remain the same. Why don’t we try it out with the Grid Plots?
The output still remains the same even if we use the three-digit format of passing the arguments.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Visualizing Tiff File Using Matplotlib and GDAL using Python
- Violinplot in Python using axes class of Matplotlib
- 3D Wireframe plotting in Python using Matplotlib
- Python | Matplotlib Sub plotting using object oriented API
- Python | Working with PNG Images using Matplotlib
- Python | Matplotlib Graph plotting using object oriented API
- Python | Visualize graphs generated in NetworkX using Matplotlib
- Python | Basic Gantt chart using Matplotlib
- Make a violin plot in Python using Matplotlib
- Plot the magnitude spectrum in Python using Matplotlib
- Plot the phase spectrum in Python using Matplotlib
- Plot Mathematical Expressions in Python using Matplotlib
- 3D Contour Plotting in Python using Matplotlib
- Make filled polygons between two curves in Python using Matplotlib
- Errorbar graph in Python using Matplotlib
- Plot the power spectral density using Matplotlib - Python
- Contour Plot using Matplotlib - Python
- How To Visualize Sparse Matrix in Python using Matplotlib?
- Plotting Histogram in Python using Matplotlib
- Box Plot in Python using Matplotlib
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.