- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 zoom subplots together in Matplotlib/Pyplot?
We can use the attribute sharex = "ax1", and then, use the subplot method to zoom the subplots together.
Steps
Add a subplot to the current figure with (nrow = 1, ncols = 2, index = 1).
Add line on the current subplot with (nrow = 1, ncols = 2, index = 1).
Add a subplot to the current figure with (nrow = 1, ncols = 2, index = 2).
Add line on the current subplot with (nrow = 1, ncols = 2, index = 2), where sharex can help to share the x or y `~matplotlib.axis` with sharex and/or sharey. The axis will have the same limits, ticks, and scale as the axis of the shared axes.
Using plt.show(), show the figures.
Example
from matplotlib import pyplot as plt ax1 = plt.subplot(1, 2, 1) ax1.plot([1, 4, 9]) ax2 = plt.subplot(1, 2, 2, sharex=ax1) ax2.plot([1, 8, 27]) plt.show()
Output
- Related Articles
- How to Zoom with Axes3D in Matplotlib?
- Plotting a horizontal line on multiple subplots in Python using pyplot
- How is the Pyplot histogram bins interpreted? (Matplotlib)
- How to share secondary Y-axis between subplots in Matplotlib?
- How to set same scale for subplots in Python using Matplotlib?
- How to increase the spacing between subplots in Matplotlib with subplot2grid?
- How to combine several matplotlib axes subplots into one figure?
- How to decrease the density of tick labels in subplots in Matplotlib?
- How can I attach a pyplot function to a figure instance? (Matplotlib)
- How to fill the area under a step curve using pyplot? (Matplotlib)
- How to make more than 10 subplots in a figure using Matplotlib?
- Embedding small plots inside subplots in Matplotlib
- Manipulation on vertical space in Matplotlib subplots
- Manipulation on horizontal space in Matplotlib subplots
- Draw a border around subplots in Matplotlib

Advertisements