- 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 should I pass a matplotlib object through a function; as Axis, Axes or Figure?
To pass a matplotlib object through a function; as Axis, Axes or figure, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- In plot() method, plot x and y data points at axes ax.
- In profile() method, create a figure and a set of subplots. Iterate the axes and pass in plot() method to plot the figure.
- Call the profile() method with 3 rows and 4 columns.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def plot(ax, x, y): ax.plot(x, y) def profile(rows, cols): fig, axes = plt.subplots(rows, cols) for ax in axes: for a in ax: plot(a, np.random.rand(10), np.random.rand(10)) profile(3, 4) plt.show()
Output
It will produce the following output
- Related Articles
- How to pass an object as a parameter in JavaScript function?
- How to pass a json object as a parameter to a python function?
- What exactly is a Matplotlib axes object?
- How can I attach a pyplot function to a figure instance? (Matplotlib)
- How do I plot multiple X or Y axes in Matplotlib?
- How to pass Python function as a function argument?
- How to pass a function as a parameter in Java
- How can I change the font size of ticks of axes object in Matplotlib?
- How to combine several matplotlib axes subplots into one figure?
- What is the difference between drawing plots using plot, axes or figure in matplotlib?
- How to draw axis in the middle of a figure in Matplotlib?
- How to pass a dictionary as argument in Python function?
- How to rotate a simple matplotlib Axes?
- How to cycle through both colours and linestyles on a matplotlib figure?
- How to remove a frame without removing the axes tick labels from a Matplotlib figure in Python?

Advertisements