
- Matplotlib - Home
- Matplotlib - Introduction
- Matplotlib - Vs Seaborn
- Matplotlib - Environment Setup
- Matplotlib - Anaconda distribution
- Matplotlib - Jupyter Notebook
- Matplotlib - Pyplot API
- Matplotlib - Simple Plot
- Matplotlib - Saving Figures
- Matplotlib - Markers
- Matplotlib - Figures
- Matplotlib - Styles
- Matplotlib - Legends
- Matplotlib - Colors
- Matplotlib - Colormaps
- Matplotlib - Colormap Normalization
- Matplotlib - Choosing Colormaps
- Matplotlib - Colorbars
- Matplotlib - Working With Text
- Matplotlib - Text properties
- Matplotlib - Subplot Titles
- Matplotlib - Images
- Matplotlib - Image Masking
- Matplotlib - Annotations
- Matplotlib - Arrows
- Matplotlib - Fonts
- Matplotlib - Font Indexing
- Matplotlib - Font Properties
- Matplotlib - Scales
- Matplotlib - LaTeX
- Matplotlib - LaTeX Text Formatting in Annotations
- Matplotlib - PostScript
- Matplotlib - Mathematical Expressions
- Matplotlib - Animations
- Matplotlib - Celluloid Library
- Matplotlib - Blitting
- Matplotlib - Toolkits
- Matplotlib - Artists
- Matplotlib - Styling with Cycler
- Matplotlib - Paths
- Matplotlib - Path Effects
- Matplotlib - Transforms
- Matplotlib - Ticks and Tick Labels
- Matplotlib - Radian Ticks
- Matplotlib - Dateticks
- Matplotlib - Tick Formatters
- Matplotlib - Tick Locators
- Matplotlib - Basic Units
- Matplotlib - Autoscaling
- Matplotlib - Reverse Axes
- Matplotlib - Logarithmic Axes
- Matplotlib - Symlog
- Matplotlib - Unit Handling
- Matplotlib - Ellipse with Units
- Matplotlib - Spines
- Matplotlib - Axis Ranges
- Matplotlib - Axis Scales
- Matplotlib - Axis Ticks
- Matplotlib - Formatting Axes
- Matplotlib - Axes Class
- Matplotlib - Twin Axes
- Matplotlib - Figure Class
- Matplotlib - Multiplots
- Matplotlib - Grids
- Matplotlib - Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Subplots() Function
- Matplotlib - Subplot2grid() Function
- Matplotlib - Anchored Artists
- Matplotlib - Manual Contour
- Matplotlib - Coords Report
- Matplotlib - AGG filter
- Matplotlib - Ribbon Box
- Matplotlib - Fill Spiral
- Matplotlib - Findobj Demo
- Matplotlib - Hyperlinks
- Matplotlib - Image Thumbnail
- Matplotlib - Plotting with Keywords
- Matplotlib - Create Logo
- Matplotlib - Multipage PDF
- Matplotlib - Multiprocessing
- Matplotlib - Print Stdout
- Matplotlib - Compound Path
- Matplotlib - Sankey Class
- Matplotlib - MRI with EEG
- Matplotlib - Stylesheets
- Matplotlib - Background Colors
- Matplotlib - Basemap
- Matplotlib - Event Handling
- Matplotlib - Close Event
- Matplotlib - Mouse Move
- Matplotlib - Click Events
- Matplotlib - Scroll Event
- Matplotlib - Keypress Event
- Matplotlib - Pick Event
- Matplotlib - Looking Glass
- Matplotlib - Path Editor
- Matplotlib - Poly Editor
- Matplotlib - Timers
- Matplotlib - Viewlims
- Matplotlib - Zoom Window
- Matplotlib Widgets
- Matplotlib - Cursor Widget
- Matplotlib - Annotated Cursor
- Matplotlib - Buttons Widget
- Matplotlib - Check Buttons
- Matplotlib - Lasso Selector
- Matplotlib - Menu Widget
- Matplotlib - Mouse Cursor
- Matplotlib - Multicursor
- Matplotlib - Polygon Selector
- Matplotlib - Radio Buttons
- Matplotlib - RangeSlider
- Matplotlib - Rectangle Selector
- Matplotlib - Ellipse Selector
- Matplotlib - Slider Widget
- Matplotlib - Span Selector
- Matplotlib - Textbox
- Matplotlib Plotting
- Matplotlib - Line Plots
- Matplotlib - Area Plots
- Matplotlib - Bar Graphs
- Matplotlib - Histogram
- Matplotlib - Pie Chart
- Matplotlib - Scatter Plot
- Matplotlib - Box Plot
- Matplotlib - Arrow Demo
- Matplotlib - Fancy Boxes
- Matplotlib - Zorder Demo
- Matplotlib - Hatch Demo
- Matplotlib - Mmh Donuts
- Matplotlib - Ellipse Demo
- Matplotlib - Bezier Curve
- Matplotlib - Bubble Plots
- Matplotlib - Stacked Plots
- Matplotlib - Table Charts
- Matplotlib - Polar Charts
- Matplotlib - Hexagonal bin Plots
- Matplotlib - Violin Plot
- Matplotlib - Event Plot
- Matplotlib - Heatmap
- Matplotlib - Stairs Plots
- Matplotlib - Errorbar
- Matplotlib - Hinton Diagram
- Matplotlib - Contour Plot
- Matplotlib - Wireframe Plots
- Matplotlib - Surface Plots
- Matplotlib - Triangulations
- Matplotlib - Stream plot
- Matplotlib - Ishikawa Diagram
- Matplotlib - 3D Plotting
- Matplotlib - 3D Lines
- Matplotlib - 3D Scatter Plots
- Matplotlib - 3D Contour Plot
- Matplotlib - 3D Bar Plots
- Matplotlib - 3D Wireframe Plot
- Matplotlib - 3D Surface Plot
- Matplotlib - 3D Vignettes
- Matplotlib - 3D Volumes
- Matplotlib - 3D Voxels
- Matplotlib - Time Plots and Signals
- Matplotlib - Filled Plots
- Matplotlib - Step Plots
- Matplotlib - XKCD Style
- Matplotlib - Quiver Plot
- Matplotlib - Stem Plots
- Matplotlib - Visualizing Vectors
- Matplotlib - Audio Visualization
- Matplotlib - Audio Processing
- Matplotlib Useful Resources
- Matplotlib - Quick Guide
- Matplotlib - Cheatsheet
- Matplotlib - Useful Resources
- Matplotlib - Discussion
Matplotlib - Multiplots
In general data visualization and plotting, multiplots, or multiple plots, refer to the creation of more than one plot within a single figure or canvas. These are useful when you want to compare different datasets or visualize various aspects of the same data.
The below image represents the 4 different plots in a single figure −

Multiplots in Matplotlib
Matplotlib provides tools for creating multiplots, and the most common approach is through the use of subplots. The subplot() is a function available in the pyplot module, and it provides good control over the arrangement of individual plots within the figure. For more advanced layout customization, GridSpec or Figure.add_subplot() functions can be used.
Creating Simple Multiplots
Creating simple multiplots involves the basic use of the subplot() function in Matplotlib. Simple multiplots are useful when you want to showcase different datasets or aspects of the same data in a clear and organized manner.
Example
In this example, a 2x2 grid of subplots is created, and individual data are plotted on each subplot.
import matplotlib.pyplot as plt import numpy as np # Sample Data x = np.linspace(0, 2 * np.pi, 400) y1 = np.sin(x ** 2) y2 = np.cos(x) y3 = np.tan(x) y4 = np.exp(-x) * np.sin(2 * np.pi * x) # Creating a 2x2 grid of subplots fig, axs = plt.subplots(2, 2, figsize=(7,4)) # Plot data on individual subplots axs[0, 0].plot(x, y1) axs[0, 1].plot(x, y2, color='orange') axs[1, 0].plot(x, y3, color='green') axs[1, 1].plot(x, y4, color='red') # Set titles to subplots axs[0, 0].set_title('Sin Plot') axs[0, 1].set_title('Cos Plot') axs[1, 0].set_title('Tan Plot') axs[1, 1].set_title('Exponential Plot') # Display the Multiplots plt.tight_layout() plt.show()
Output
On executing the above code we will get the following output −

Stacked Multiplots
Stacked multiplots are nothing but arranging subplots in one direction either vertically(top-and-bottom) or horizontally(side-by-side). When stacking in one direction, the plt.subplots() function returns a 1D NumPy array.
Example
This example creates two vertically stacked subplots, each showcasing different plots.
import matplotlib.pyplot as plt import numpy as np # Sample Data x = np.linspace(0, 2 * np.pi, 400) y1 = np.sin(x**2) y2 = np.cos(x**2) # Creating vertically stacked subplots fig, axs = plt.subplots(2, figsize=(7,4)) fig.suptitle('Vertically stacked subplots') # Plotting data on individual subplots axs[0].plot(x, y1) axs[1].plot(x, y2) # Adding titles to subplots axs[0].set_title('Sin Plot') axs[1].set_title('Cos Plot') # Adjust the layout plt.tight_layout() # Displaying the multiplot plt.show()
Output
On executing the above code we will get the following output −

Multiplots with Sharing Axes
By default, each subplot Axes is scaled individually. For sharing axes between subplots you can use the sharex and sharey parameters of the plt.subplots() function.
Example
This example creates two Horizontally stacked subplots with a shared y-axis.
import matplotlib.pyplot as plt import numpy as np # Sample Data x = np.linspace(0, 2 * np.pi, 400) y1 = np.sin(x ** 2) y2 = np.cos(x) # Creating subplots with shared y-axis fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(7, 4)) fig.suptitle('Multiplots with Shared y-Axis') # Plotting data on individual subplots ax1.plot(x, y1) ax2.plot(x, y2) # Adding titles to subplots ax1.set_title('Sin Plot') ax2.set_title('Cos Plot') # Adjust the layout plt.tight_layout() # Display the multiplots plt.show()
Output
On executing the above code we will get the following output −
