
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to combine several matplotlib axes subplots into one figure?
To combine several matplotlib axes subplots into one figure, we can use subplots() method with nrow=2.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create x, y1 and y2 data points using numpy.
- Create a figure and a set of subplots.
- Plot x, y1 and y2 data points using plot() method.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-10, 10, 100) y1 = np.sin(x) y2 = np.cos(x) fig, axes = plt.subplots(nrows=2) line1, = axes[0].plot(x, y1, color='red') line2, = axes[1].plot(x, y2, color='green') plt.show()
Output
- Related Articles
- How to share x axes of two subplots after they have been created in Matplotlib?
- How to make more than 10 subplots in a figure using Matplotlib?
- How to annotate several points with one text in Matplotlib?
- Annotate Subplots in a Figure with A, B, C using Matplotlib
- How to Combine Data from Multiple Excel Worksheets into One?
- How to combine worksheets of same name into one worksheet?
- What is the preferred way to set Matplotlib figure/axes properties?
- How to zoom subplots together in Matplotlib/Pyplot?
- How to switch axes in Matplotlib?
- How to programmatically add buttons into a layout one by one in several lines in Android
- How to make axes transparent in Matplotlib?
- How to rotate a simple matplotlib Axes?
- How to show multiple images in one figure in Matplotlib?
- How do I show the same Matplotlib figure several times in a single IPython notebook?
- Excel Tutorial: Combine Multiple Workbooks/Worksheets into One

Advertisements