Basic principles and structures
Matplotlib Basics
3 min read
Published Oct 5 2025
Guide Sections
Guide Comments
The Basic Structure of a Matplotlib Chart
At its core, Matplotlib’s architecture is object-oriented.
Every plot is made of nested objects that together describe what to draw and how to draw it.
Figure - main canvas
- A Figure is the entire plotting window or page.
- It’s the top-level container — think of it as the paper or canvas.
- You can have multiple figures open at once, and each can contain one or more plots.
- If you have multiple figures open and then show them, each figure is displayed in its own window, where as if you add multiple plots on a single figure they will all be displayed in the same window.
- There are properties that you can set for overall figure (canvas) title, background colours, size of the canvas etc.
Axes — the actual plot area
- An Axes is a single plot or chart inside the figure.
- It defines:
- The data coordinate system
- The x- and y-axis lines
- The labels, titles, ticks, etc.
- Each Figure can have one or more Axes (e.g., subplots).
Axis — The Number Line(s) of the Axes
- Inside each Axes, there are Axis objects:
xaxis
→ controls the x scale, ticks, labelsyaxis
→ controls the y scale, ticks, labels
Artist — Anything That Gets Drawn
- Every visible element in a plot is an Artist.
- Lines (
Line2D
) - Text labels (
Text
) - Shapes (
Patch
) - Images, Legends, Titles, Ticks, etc.
- Lines (
- Even the Figure and Axes themselves are actually Artists
Matplotlib Object Hierarchy:
- Figure - (overall canvas)
- Axes - (individual plot area or chart)
- Axis - (x and y coordinate systems)
- Artists (everything drawn: lines, text, shapes, etc.)
Automatic vs Manual Creation
Matplotlib can build all the structure for you, or you can manually construct it step-by-step.
Automatic
Matplotlib automatically:
- Creates a Figure
- Creates an Axes
- Adds a Line2D Artist
- Draws it
Manual (more granular control)
You can create and manage everything yourself:
plt.show()
This function will display all open figures. If there are more than 1 figure open, then it will display each of them in separate windows.
To essentially, once you have created your charts, calling this method will display it on the screen.
By default, code execution will pause when the chart windows open, and resume once all figure windows are closed. You can change this behaviour by passing the block=False
parameter to the show method.