- 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
Changing Matplotlib subplot size/position after axes creation
To change subplot size or position after axes creation, we can take the following steps−
- Create a new figure or activate an existing figure using figure() method.
- Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method.
- A grid layout to place subplots within a figure using GridSpec() class.
- Set the position of the grid specs.
- Set the subplotspec instance.
- Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method, with gridspec instance.
- Adjust the padding between and around the subplots.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt from matplotlib import gridspec as gridspec plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111) gs = gridspec.GridSpec(3, 1) ax.set_position(gs[0:2].get_position(fig)) ax.set_subplotspec(gs[0:2]) fig.add_subplot(gs[2]) fig.tight_layout() plt.show()
Output
- Related Articles
- Setting active subplot using axes object in Matplotlib
- Displaying different images with actual size in a Matplotlib subplot
- Matplotlib legends in subplot
- How to show an Axes Subplot in Python?
- Automated legend creation in Matplotlib
- How can I change the font size of ticks of axes object in Matplotlib?
- Stuffing a Pandas DataFrame.plot into a Matplotlib subplot
- Rotating axis text for each subplot in Matplotlib
- How to share x axes of two subplots after they have been created in Matplotlib?
- How to make longer subplot tick marks in Matplotlib?
- Java Program to change JLabel text after creation
- How to switch axes in Matplotlib?
- Change x axes scale in matplotlib
- How to rotate tick labels in a subplot in Matplotlib?
- How to plot multiple Seaborn Jointplot in Subplot using Matplotlib?

Advertisements