- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot multiple graphs in Matplotlib?
To plot multiple graphs in matplotlib, we will use the following steps −
Steps
Create x, y1 and y2 data points using numpy.
Add a subplot to the current figure at index 1.
Plot curve 1 using x and y1.
Add a subplot to the current figure at index 2.
Plot curve 2 using x and y2.
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(-2, 2, 10) y1 = np.sin(x) y2 = np.cos(x) plt.subplot(211) plt.plot(y1) plt.subplot(212) plt.plot(y2) plt.show()
Output
- Related Articles
- How to plot 3D graphs using Python Matplotlib?
- How to plot multiple Seaborn Jointplot in Subplot using Matplotlib?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to plot bar graphs with same X coordinates side by side in Matplotlib?
- Plotting multiple line graphs using Pandas and Matplotlib
- How to plot a Bar Chart with multiple labels in Matplotlib?
- How to plot multiple horizontal bars in one chart with matplotlib?
- How to combine multiple graphs in Python
- How to plot with multiple color cycle using cycler property in Matplotlib
- How do I plot two countplot graphs side by side in Seaborn using Matplotlib?
- How do I plot multiple X or Y axes in Matplotlib?
- How to plot data from multiple two-column text files with legends in Matplotlib?
- How to create broken horizontal bar graphs in matplotlib?
- Plot multiple boxplots in one graph in Pandas or Matplotlib
- How to a plot stem plot in Matplotlib Python?

Advertisements