A Figure in Matplotlib is the outer container for a plot — analogous to a sheet of paper. It owns all the visual elements: the axes that contain the actual data, the title, the legend, the colors, the layout. Everything that ends up on the rendered page sits inside the Figure.
Two common ways to create one:
import matplotlib.pyplot as plt
fig1 = plt.figure() # empty Figure, no Axes inside it
fig2, ax2 = plt.subplots() # Figure plus a single Axesplt.figure() creates a Figure and nothing else. You’d typically follow it with code that adds Axes manually — useful for irregular layouts. plt.subplots() is the convenient form: it makes a Figure, adds a single Axes inside, and returns both. The tuple unpacking fig, ax = plt.subplots() is the standard idiom and what most code uses.
For multi-Axes layouts:
fig, axs = plt.subplots(2, 2) # 2×2 grid of Axes
fig, axs = plt.subplots(1, 3, figsize=(15, 5)) # 1 row × 3 columnsFor irregular layouts where some Axes span multiple cells, GridSpec is the tool.
The Figure has its own properties — overall size in inches (figsize), DPI for raster output, title (fig.suptitle(...)) — separate from those of any individual Axes. Saving the rendered plot to a file is a Figure operation: fig.savefig('out.png', dpi=300). Showing it interactively is plt.show() (which displays whichever Figures are currently open).
The Figure–Axes split is the central conceptual distinction in Matplotlib. Figure is the canvas; Axes are the charts drawn on it. Plotting commands almost always target an Axes; layout and export commands target the Figure.