On this page
matplotlib.pyplot.figure
- matplotlib.pyplot.figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, FigureClass=<class 'matplotlib.figure.Figure'>, clear=False, **kwargs)[source]
-
Create a new figure, or activate an existing figure.
- Parameters
-
- numint or str or
Figure, optional -
A unique identifier for the figure.
If a figure with that identifier already exists, this figure is made active and returned. An integer refers to the
Figure.numberattribute, a string refers to the figure label.If there is no figure with the identifier or num is not given, a new figure is created, made active and returned. If num is an int, it will be used for the
Figure.numberattribute, otherwise, an auto-generated integer value is used (starting at 1 and incremented for each new figure). If num is a string, the figure label and the window title is set to this value. - figsize(float, float), default:
rcParams["figure.figsize"](default:[6.4, 4.8]) -
Width, height in inches.
- dpifloat, default:
rcParams["figure.dpi"](default:100.0) -
The resolution of the figure in dots-per-inch.
- facecolorcolor, default:
rcParams["figure.facecolor"](default:'white') -
The background color.
- edgecolorcolor, default:
rcParams["figure.edgecolor"](default:'white') -
The border color.
- frameonbool, default: True
-
If False, suppress drawing the figure frame.
- FigureClasssubclass of
Figure -
Optionally use a custom
Figureinstance. - clearbool, default: False
-
If True and the figure already exists, then it is cleared.
- tight_layoutbool or dict, default:
rcParams["figure.autolayout"](default:False) -
If
Falseuse subplotpars. IfTrueadjust subplot parameters usingtight_layoutwith default padding. When providing a dict containing the keyspad,w_pad,h_pad, andrect, the defaulttight_layoutpaddings will be overridden. - constrained_layoutbool, default:
rcParams["figure.constrained_layout.use"](default:False) -
If
Trueuse constrained layout to adjust positioning of plot elements. Liketight_layout, but designed to be more flexible. See Constrained Layout Guide for examples. (Note: does not work withadd_subplotorsubplot2grid.) - **kwargs : optional
-
See
Figurefor other possible arguments.
- numint or str or
- Returns
Notes
If you are creating many figures, make sure you explicitly call
pyplot.closeon the figures you are not using, because this will enable pyplot to properly clean up the memory.rcParamsdefines the default values, which can be modified in the matplotlibrc file.
Examples using matplotlib.pyplot.figure
© 2012–2021 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.pyplot.figure.html