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
orSubFigure
, 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.number
attribute, 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.number
attribute, 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. If num is aSubFigure
, its parentFigure
is activated.- 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
If set, an instance of this subclass will be created, rather than a plain
Figure
.- clearbool, default: False
If True and the figure already exists, then it is cleared.
- layout{'constrained', 'tight',
LayoutEngine
, None}, default: None The layout mechanism for positioning of plot elements to avoid overlapping Axes decorations (labels, ticks, etc). Note that layout managers can measurably slow down figure display. Defaults to None (but see the documentation of the
Figure
constructor regarding the interaction with rcParams).- **kwargs
Additional keyword arguments are passed to the
Figure
constructor.
- numint or str or
- Returns:
Notes
Newly created figures are passed to the
new_manager
method or thenew_figure_manager
function provided by the current backend, which install a canvas and a manager on the figure.If you are creating many figures, make sure you explicitly call
pyplot.close
on the figures you are not using, because this will enable pyplot to properly clean up the memory.rcParams
defines the default values, which can be modified in the matplotlibrc file.
Examples using matplotlib.pyplot.figure
#
Resizing axes with constrained layout
Resizing axes with tight layout
Using Gridspec to make multi-column/row subplot layouts
Managing multiple figures in pyplot
Creating multiple subplots using plt.subplots
The difference between \dfrac and \frac
Annotation arrow style reference
Fonts demo (object-oriented style)
Fonts demo (keyword arguments)
Showing RGB channels using RGBAxes
Per-row or per-column colorbars
Axes with a fixed physical size
Setting a fixed aspect on ImageGrid cells
Make room for ylabel using axes_grid
mpl_toolkits.axisartist.floating_axes features
Shaded & power normalized rendering
Create 2D bar graphs in different planes
Demonstrates plotting contour (level) curves in 3D
Demonstrates plotting contour (level) curves in 3D using the extend3d option
Projecting contour profiles onto a graph
Projecting filled contour onto a graph
Create 3D histogram of 2D data
Generate polygons to fill under 3D line graph
3D surface with polar coordinates
Triangular 3D filled contour plot
3D voxel plot of the numpy logo
3D voxel / volumetric plot with rgb colors
3D voxel / volumetric plot with cylindrical coordinates
Long chain of connections using Sankey
SkewT-logP diagram: using transforms and custom projections
Rectangle and ellipse selectors
Arranging multiple Axes in a Figure
Complex and semantic figure composition