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 or SubFigure, 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 a SubFigure, its parent Figure 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.

Returns:
Figure

Notes

Newly created figures are passed to the new_manager method or the new_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#

Curve with error band

Curve with error band

Curve with error band
Errorbar limit selection

Errorbar limit selection

Errorbar limit selection
EventCollection Demo

EventCollection Demo

EventCollection Demo
Filled polygon

Filled polygon

Filled polygon
Scatter plot with histograms

Scatter plot with histograms

Scatter plot with histograms
Barcode

Barcode

Barcode
Figimage Demo

Figimage Demo

Figimage Demo
Layer Images

Layer Images

Layer Images
Aligning Labels

Aligning Labels

Aligning Labels
Axes Zoom Effect

Axes Zoom Effect

Axes Zoom Effect
Custom Figure subclasses

Custom Figure subclasses

Custom Figure subclasses
Resizing axes with constrained layout

Resizing axes with constrained layout

Resizing axes with constrained layout
Resizing axes with tight layout

Resizing axes with tight layout

Resizing axes with tight layout
Geographic Projections

Geographic Projections

Geographic Projections
Using Gridspec to make multi-column/row subplot layouts

Using Gridspec to make multi-column/row subplot layouts

Using Gridspec to make multi-column/row subplot layouts
Nested Gridspecs

Nested Gridspecs

Nested Gridspecs
Managing multiple figures in pyplot

Managing multiple figures in pyplot

Managing multiple figures in pyplot
Figure subfigures

Figure subfigures

Figure subfigures
Creating multiple subplots using ``plt.subplots``

Creating multiple subplots using plt.subplots

Creating multiple subplots using ``plt.subplots``
Polar Legend

Polar Legend

Polar Legend
Scatter plot on polar axis

Scatter plot on polar axis

Scatter plot on polar axis
Arrow Demo

Arrow Demo

Arrow Demo
Auto-wrapping text

Auto-wrapping text

Auto-wrapping text
Text Rotation Mode

Text Rotation Mode

Text Rotation Mode
The difference between \\dfrac and \\frac

The difference between \dfrac and \frac

The difference between \\dfrac and \\frac
Annotation arrow style reference

Annotation arrow style reference

Annotation arrow style reference
Fonts demo (object-oriented style)

Fonts demo (object-oriented style)

Fonts demo (object-oriented style)
Fonts demo (keyword arguments)

Fonts demo (keyword arguments)

Fonts demo (keyword arguments)
Convert texts to images

Convert texts to images

Convert texts to images
Mathtext Examples

Mathtext Examples

Mathtext Examples
Rainbow text

Rainbow text

Rainbow text
STIX Fonts

STIX Fonts

STIX Fonts
Unicode minus

Unicode minus

Unicode minus
Usetex Baseline Test

Usetex Baseline Test

Usetex Baseline Test
Usetex Fonteffects

Usetex Fonteffects

Usetex Fonteffects
Annotation Polar

Annotation Polar

Annotation Polar
Fig Axes Customize Simple

Fig Axes Customize Simple

Fig Axes Customize Simple
Simple axes labels

Simple axes labels

Simple axes labels
Adding lines to figures

Adding lines to figures

Adding lines to figures
Pyplot Two Subplots

Pyplot Two Subplots

Pyplot Two Subplots
Text Commands

Text Commands

Text Commands
Text Layout

Text Layout

Text Layout
Drawing fancy boxes

Drawing fancy boxes

Drawing fancy boxes
Hatch demo

Hatch demo

Hatch demo
Axes Divider

Axes Divider

Axes Divider
Demo Axes Grid

Demo Axes Grid

Demo Axes Grid
Axes Grid2

Axes Grid2

Axes Grid2
Showing RGB channels using RGBAxes

Showing RGB channels using RGBAxes

Showing RGB channels using RGBAxes
Per-row or per-column colorbars

Per-row or per-column colorbars

Per-row or per-column colorbars
Axes with a fixed physical size

Axes with a fixed physical size

Axes with a fixed physical size
Setting a fixed aspect on ImageGrid cells

Setting a fixed aspect on ImageGrid cells

Setting a fixed aspect on ImageGrid cells
Inset Locator Demo

Inset Locator Demo

Inset Locator Demo
Make room for ylabel using axes_grid

Make room for ylabel using axes_grid

Make room for ylabel using axes_grid
Parasite Simple2

Parasite Simple2

Parasite Simple2
Simple Axes Divider 1

Simple Axes Divider 1

Simple Axes Divider 1
Simple Axes Divider 3

Simple Axes Divider 3

Simple Axes Divider 3
Simple ImageGrid

Simple ImageGrid

Simple ImageGrid
Simple ImageGrid 2

Simple ImageGrid 2

Simple ImageGrid 2
Axis Direction

Axis Direction

Axis Direction
axis_direction demo

axis_direction demo

axis_direction demo
Axis line styles

Axis line styles

Axis line styles
Curvilinear grid demo

Curvilinear grid demo

Curvilinear grid demo
Demo CurveLinear Grid2

Demo CurveLinear Grid2

Demo CurveLinear Grid2
:mod:`mpl_toolkits.axisartist.floating_axes` features

mpl_toolkits.axisartist.floating_axes features

:mod:`mpl_toolkits.axisartist.floating_axes` features
floating_axis demo

floating_axis demo

floating_axis demo
Parasite Axes demo

Parasite Axes demo

Parasite Axes demo
Ticklabel alignment

Ticklabel alignment

Ticklabel alignment
Ticklabel direction

Ticklabel direction

Ticklabel direction
Simple Axis Direction01

Simple Axis Direction01

Simple Axis Direction01
Simple Axis Direction03

Simple Axis Direction03

Simple Axis Direction03
Simple Axis Pad

Simple Axis Pad

Simple Axis Pad
Custom spines with axisartist

Custom spines with axisartist

Custom spines with axisartist
Simple Axisline

Simple Axisline

Simple Axisline
Simple Axisline3

Simple Axisline3

Simple Axisline3
Anatomy of a figure

Anatomy of a figure

Anatomy of a figure
Firefox

Firefox

Firefox
Shaded & power normalized rendering

Shaded & power normalized rendering

Shaded & power normalized rendering
XKCD

XKCD

XKCD
The double pendulum problem

The double pendulum problem

The double pendulum problem
Frame grabbing

Frame grabbing

Frame grabbing
Rain simulation

Rain simulation

Rain simulation
Animated 3D random walk

Animated 3D random walk

Animated 3D random walk
MATPLOTLIB **UNCHAINED**

MATPLOTLIB UNCHAINED

MATPLOTLIB **UNCHAINED**
Close Event

Close Event

Close Event
Interactive functions

Interactive functions

Interactive functions
Hyperlinks

Hyperlinks

Hyperlinks
Matplotlib logo

Matplotlib logo

Matplotlib logo
Multipage PDF

Multipage PDF

Multipage PDF
SVG Filter Line

SVG Filter Line

SVG Filter Line
SVG Filter Pie

SVG Filter Pie

SVG Filter Pie
transforms.offset_copy

transforms.offset_copy

transforms.offset_copy
Zorder Demo

Zorder Demo

Zorder Demo
Plot 2D data on 3D plot

Plot 2D data on 3D plot

Plot 2D data on 3D plot
Demo of 3D bar charts

Demo of 3D bar charts

Demo of 3D bar charts
Create 2D bar graphs in different planes

Create 2D bar graphs in different planes

Create 2D bar graphs in different planes
3D box surface plot

3D box surface plot

3D box surface plot
Demonstrates plotting contour (level) curves in 3D

Demonstrates plotting contour (level) curves in 3D

Demonstrates plotting contour (level) curves in 3D
Demonstrates plotting contour (level) curves in 3D using the extend3d option

Demonstrates plotting contour (level) curves in 3D using the extend3d option

Demonstrates plotting contour (level) curves in 3D using the extend3d option
Projecting contour profiles onto a graph

Projecting contour profiles onto a graph

Projecting contour profiles onto a graph
Filled contours

Filled contours

Filled contours
Projecting filled contour onto a graph

Projecting filled contour onto a graph

Projecting filled contour onto a graph
3D errorbars

3D errorbars

3D errorbars
Create 3D histogram of 2D data

Create 3D histogram of 2D data

Create 3D histogram of 2D data
Parametric Curve

Parametric Curve

Parametric Curve
Lorenz Attractor

Lorenz Attractor

Lorenz Attractor
2D and 3D *Axes* in same *Figure*

2D and 3D Axes in same Figure

2D and 3D *Axes* in same *Figure*
Automatic Text Offsetting

Automatic Text Offsetting

Automatic Text Offsetting
Draw flat objects in 3D plot

Draw flat objects in 3D plot

Draw flat objects in 3D plot
Generate polygons to fill under 3D line graph

Generate polygons to fill under 3D line graph

Generate polygons to fill under 3D line graph
3D quiver plot

3D quiver plot

3D quiver plot
Rotating a 3D plot

Rotating a 3D plot

Rotating a 3D plot
3D scatterplot

3D scatterplot

3D scatterplot
3D plots as subplots

3D plots as subplots

3D plots as subplots
3D surface (solid color)

3D surface (solid color)

3D surface (solid color)
3D surface (checkerboard)

3D surface (checkerboard)

3D surface (checkerboard)
3D surface with polar coordinates

3D surface with polar coordinates

3D surface with polar coordinates
Text annotations in 3D

Text annotations in 3D

Text annotations in 3D
Triangular 3D contour plot

Triangular 3D contour plot

Triangular 3D contour plot
Triangular 3D filled contour plot

Triangular 3D filled contour plot

Triangular 3D filled contour plot
Triangular 3D surfaces

Triangular 3D surfaces

Triangular 3D surfaces
More triangular 3D surfaces

More triangular 3D surfaces

More triangular 3D surfaces
3D voxel / volumetric plot

3D voxel / volumetric plot

3D voxel / volumetric plot
3D voxel plot of the numpy logo

3D voxel plot of the numpy logo

3D voxel plot of the numpy logo
3D voxel / volumetric plot with rgb colors

3D voxel / volumetric plot with rgb colors

3D voxel / volumetric plot with rgb colors
3D voxel / volumetric plot with cylindrical coordinates

3D voxel / volumetric plot with cylindrical coordinates

3D voxel / volumetric plot with cylindrical coordinates
3D wireframe plot

3D wireframe plot

3D wireframe plot
Animating a 3D wireframe plot

Animating a 3D wireframe plot

Animating a 3D wireframe plot
Asinh Demo

Asinh Demo

Asinh Demo
MRI with EEG

MRI with EEG

MRI with EEG
The Sankey class

The Sankey class

The Sankey class
Long chain of connections using Sankey

Long chain of connections using Sankey

Long chain of connections using Sankey
Rankine power cycle

Rankine power cycle

Rankine power cycle
SkewT-logP diagram: using transforms and custom projections

SkewT-logP diagram: using transforms and custom projections

SkewT-logP diagram: using transforms and custom projections
Spine Placement

Spine Placement

Spine Placement
Ellipse with units

Ellipse with units

Ellipse with units
SVG Histogram

SVG Histogram

SVG Histogram
Tool Manager

Tool Manager

Tool Manager
subplot2grid demo

subplot2grid demo

subplot2grid demo
GridSpec demo

GridSpec demo

GridSpec demo
Nested GridSpecs

Nested GridSpecs

Nested GridSpecs
Simple Legend01

Simple Legend01

Simple Legend01
Menu

Menu

Menu
Rectangle and ellipse selectors

Rectangle and ellipse selectors

Rectangle and ellipse selectors
Pyplot tutorial

Pyplot tutorial

Pyplot tutorial
Image tutorial

Image tutorial

Image tutorial
Quick start guide

Quick start guide

Quick start guide
Artist tutorial

Artist tutorial

Artist tutorial
Constrained Layout Guide

Constrained Layout Guide

Constrained Layout Guide
Tight Layout guide

Tight Layout guide

Tight Layout guide
Arranging multiple Axes in a Figure

Arranging multiple Axes in a Figure

Arranging multiple Axes in a Figure
*origin* and *extent* in `~.Axes.imshow`

origin and extent in imshow

*origin* and *extent* in `~.Axes.imshow`
Path effects guide

Path effects guide

Path effects guide
Transformations Tutorial

Transformations Tutorial

Transformations Tutorial
Specifying Colors

Specifying Colors

Specifying Colors
Complex and semantic figure composition

Complex and semantic figure composition

Complex and semantic figure composition
Text in Matplotlib Plots

Text in Matplotlib Plots

Text in Matplotlib Plots
Text properties and layout

Text properties and layout

Text properties and layout