Figure (Matplotlib)

A Figure is the top-level container for an entire Matplotlib drawing — the whole window or page that holds one or more Axes (plots), plus any titles, legends, and colorbars. Everything you draw lives inside a Figure.

Matplotlib

Think of the Figure as the canvas and the Axes as the individual charts painted on it. A Figure can hold a single plot or a grid of many, and it owns figure-wide elements like the overall title (suptitle) and the page-level layout. You usually create one with plt.subplots() or plt.figure().

The Figure controls the output: its size in inches (figsize) and dots-per-inch (dpi) determine how large and sharp a saved image is, and fig.savefig() writes the whole thing to a file. When you call plt.savefig you are really saving the current Figure.

Keeping the Figure and its Axes as named variables (the object-oriented style) is the recommended way to build complex multi-panel plots, because it makes clear which chart each command affects.

Syntax

fig = plt.figure(figsize=(w, h))  |  fig, ax = plt.subplots()

Examples

Python

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
print(type(fig).__name__)

Output:

Figure

Learn it in a lesson

See also

Back to the Dictionary