Python:Matplotlib .figure()
Anonymous contributor
Published Oct 29, 2025
Contribute to Docs
The .figure() function in Matplotlib creates a new top-level container, called a figure, which acts as the canvas for all plots and axes in Matplotlib. If a figure with the given identifier already exists, it makes that figure active instead.
Syntax
matplotlib.pyplot.figure(
num=None,
figsize=None,
dpi=None,
facecolor=None,
edgecolor=None,
frameon=True,
FigureClass=<class 'matplotlib.figure.Figure'>,
clear=False,
**kwargs
)
Parameters:
num(int or str, optional): Identifier for the figure. If the number or name already exists, that figure becomes active; otherwise, a new one is created.figsize(tuple, optional): Width and height of the figure in inches, e.g.(8, 6).dpi(float, optional): Dots per inch; controls the resolution of the figure.facecolor(color, optional): Background color of the figure.edgecolor(color, optional): Border color of the figure.frameon(bool, default: True): Whether to draw the figure frame.FigureClass(Figuresubclass, optional): The class used to create the figure instance. Defaults tomatplotlib.figure.Figure.clear(bool, default: False): IfTrue, clears the existing figure before reusing it.**kwargs: Additional parameters passed to theFigureconstructor.
Return value:
Returns a Figure object, which is the main container that holds all plot elements like axes, titles, labels, and legends.
Example
This example creates a new figure canvas with a specific size and background color, then adds a simple sine wave plot to it:
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0, 2 * np.pi, 100)y = np.sin(x)plt.figure(figsize=(8, 4), facecolor='lightblue')ax = plt.subplot(1, 1, 1)ax.plot(x, y)ax.set_title('Simple Sine Wave')ax.set_xlabel('X-axis')ax.set_ylabel('Y-axis')plt.show()
The output of this code is:

All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Matplotlib on Codecademy
- Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
- Includes 27 Courses
- With Professional Certification
- Beginner Friendly.95 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours