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
FigureorSubFigure, optional A unique identifier for the figure.
If a figure with that identifier already exists, this figure is madeactive and returned. An integer refers to the
Figure.numberattribute, a string refers to the figure label.If there is no figure with the identifier ornum is not given, a newfigure is created, made active and returned. Ifnum is an int, itwill be used for the
Figure.numberattribute, otherwise, anauto-generated integer value is used (starting at 1 and incrementedfor each new figure). Ifnum is a string, the figure label and thewindow title is set to this value. If num is aSubFigure, itsparentFigureis 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 aplain
Figure.- clearbool, default: False
If True and the figure already exists, then it is cleared.
- layout{'constrained', 'compressed', 'tight', 'none',
LayoutEngine, None}, default: None The layout mechanism for positioning of plot elements to avoidoverlapping Axes decorations (labels, ticks, etc). Note that layoutmanagers can measurably slow down figure display.
'constrained': The constrained layout solver adjusts Axes sizesto avoid overlapping Axes decorations. Can handle complex plotlayouts and colorbars, and is thus recommended.
SeeConstrained layout guidefor examples.
'compressed': uses the same algorithm as 'constrained', butremoves extra space between fixed-aspect-ratio Axes. Best forsimple grids of Axes.
'tight': Use the tight layout mechanism. This is a relativelysimple algorithm that adjusts the subplot parameters so thatdecorations do not overlap. See
Figure.set_tight_layoutforfurther details.'none': Do not use a layout engine.
A
LayoutEngineinstance. Builtin layout classes areConstrainedLayoutEngineandTightLayoutEngine, more easilyaccessible by 'constrained' and 'tight'. Passing an instanceallows third parties to provide their own layout engine.
If not given, fall back to using the parameterstight_layout andconstrained_layout, including their config defaults
rcParams["figure.autolayout"](default:False) andrcParams["figure.constrained_layout.use"](default:False).- **kwargs
Additional keyword arguments are passed to the
Figureconstructor.
- numint or str or
- Returns:
Notes
A newly created figure is passed to the
new_managermethod or thenew_figure_managerfunction provided by the currentbackend, which install a canvas and a manager on the figure.Once this is done,
rcParams["figure.hooks"](default:[]) are called, one at a time, on thefigure; these hooks allow arbitrary customization of the figure (e.g.,attaching callbacks) or of associated elements (e.g., modifying thetoolbar). Seemplcvd -- an example of figure hook for an example oftoolbar customization.If you are creating many figures, make sure you explicitly call
pyplot.closeon the figures you are not using, because this willenable pyplot to properly clean up the memory.rcParamsdefines the default values, which can be modifiedin the matplotlibrc file.
Examples usingmatplotlib.pyplot.figure#
Plot contour (level) curves in 3D using the extend3d option
3D voxel / volumetric plot with cylindrical coordinates
SkewT-logP diagram: using transforms and custom projections
Concatenate text objects with different properties
Complex and semantic figure composition (subplot_mosaic)