- 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 remove the space between subplots in Matplotlib.pyplot?
To remove the space between subplots in matplotlib, we can use GridSpec(3, 3) class and add axes as a subplot arrangement.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Add a grid layout to place subplots within a figure.
- Update the subplot parameters of the grid
- Iterate in the range of dimension of grid specs.
- Add a subplot to the current figure.
- Set the aspect ratios.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True gs1 = gridspec.GridSpec(3, 3) gs1.update(wspace=0.5, hspace=0.1) for i in range(9): ax1 = plt.subplot(gs1[i]) ax1.set_aspect('equal') plt.show()
Output
- Related Articles
- How to zoom subplots together in Matplotlib/Pyplot?
- How to adjust the space between Matplotlib/Seaborn subplots for multi-plot layouts?
- Manipulation on vertical space in Matplotlib subplots
- Manipulation on horizontal space in Matplotlib subplots
- How to increase the spacing between subplots in Matplotlib with subplot2grid?
- How to share secondary Y-axis between subplots in Matplotlib?
- How to remove the space between inline-block elements?
- How is the Pyplot histogram bins interpreted? (Matplotlib)
- Plotting a horizontal line on multiple subplots in Python using pyplot
- How to remove random unwanted space in LaTeX-style maths in matplotlib plot?
- How to remove the space between inline/inline-block elements in HTML?
- How to adjust the space between legend markers and labels in Matplotlib?
- How to decrease the density of tick labels in subplots in Matplotlib?
- How do I close all the open pyplot windows (Matplotlib)?
- How to fill the area under a step curve using pyplot? (Matplotlib)

Advertisements