- 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
Setting active subplot using axes object in Matplotlib
To set active subplot axes object in matplotlib, we can use subplots() method to add the axes as a subplot arrangement.
Steps
Set the figure size and adjust the padding between and around the subplots.
Create x and y lists for data points.
Create a figure and a set of subplots using subplots() method with one row and two columns.
Add an axes to the current figure and make it the current axes, with axis object at the 0th index.
Plot x and y data points using plot() method.
Add an axes to the current figure and make it the current axes, with axis object at the 1st index.
Plot x and y data points using plot() method.
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 x = [1, 2, 4, 2, 1] y = [1, 4, 0, 4, 1] fig, axs = plt.subplots(1, 2) plt.axes(axs[0]) plt.plot(x, y) plt.axes(axs[1]) plt.plot(y, x) plt.show()
Output
- Related Articles
- Changing Matplotlib subplot size/position after axes creation
- Matplotlib legends in subplot
- How to show an Axes Subplot in Python?
- What exactly is a Matplotlib axes object?
- How to plot multiple Seaborn Jointplot in Subplot using Matplotlib?
- Setting Y-axis in Matplotlib using Pandas
- Active product sales analysis using matplotlib in Python
- Remove white border when using subplot and imshow in Python Matplotlib
- Rotating axis text for each subplot in Matplotlib
- How to make longer subplot tick marks in Matplotlib?
- Change x axes scale in matplotlib
- How to switch axes in Matplotlib?
- How can I change the font size of ticks of axes object in Matplotlib?
- How to rotate tick labels in a subplot in Matplotlib?
- Setting the Matplotlib title in bold while using "Times New Roman"

Advertisements