- 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 get multiple overlapping plots with independent scaling in Matplotlib?
To get multiple overlapping plots with independent scaling in Matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create a figure and a set of subplots.
Plot a list of data points using plot() method on a seperate Y-axis and overlapping X-axis.
Create a twin Axes sharing the X-axis.
Plot a list of data points using plot() method on a seperate Y-axis and overlapping X-axis.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax1 = plt.subplots() ax1.plot([1, 2, 3, 4, 5], color='red') ax2 = ax1.twinx() ax2.plot([11, 12, 31, 41, 15], color='blue') plt.show()
Output
- Related Articles
- Defining multiple plots to be animated with a for loop in Matplotlib
- How can Matplotlib be used to create multiple plots iteratively in Python?
- How to align multiple plots in a grid using GridSpec Class in Matplotlib
- How to plot overlapping lines in Matplotlib?
- How to reuse plots in Matplotlib?
- Adding a legend to a Matplotlib boxplot with multiple plots on the same axis
- How to avoid overlapping error bars in matplotlib?
- How do I get interactive plots again in Spyder/Ipython/matplotlib?
- How can multiple plots be plotted in same figure using matplotlib and Python?
- How to add annotations in Matplotlib Plots?
- How to show multiple ggplot2 plots with Plotly using R?
- Logscale plots with zero values in Matplotlib
- How to display print statements interlaced with Matplotlib plots inline in iPython?
- How to save Matplotlib 3d rotating plots?
- How to create multiple series scatter plots with connected points using seaborn?

Advertisements