The Figure & Axes
Matplotlib is a Python library for creating charts and visualizations — and every chart you draw lives inside two objects: a Figure (the whole canvas) and one or more Axes (the individual plot areas).
Learn The Figure & Axes in our free Matplotlib course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.
Part of the free Matplotlib course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
In this lesson you'll meet fig, ax = plt.subplots() and learn the difference between the quick pyplot interface and the explicit object-oriented interface.
Think of the Figure as a blank sheet of paper and an Axes as a single chart drawn on that paper. A Figure can hold one Axes or a whole grid of them, but each Axes has its own data, x-axis, and y-axis.
The cleanest way to get both at once is plt.subplots() , which returns a Figure and an Axes together so you always know exactly which object you're working with.
What you'll see: a single chart with a blue line that rises, dips, peaks at x=4, then eases down. It looks just like a normal plot — but now you hold explicit references to the Figure ( fig ) and the Axes ( ax ).
Matplotlib offers two ways to build the same chart. The pyplot interface ( plt.plot ) quietly tracks a "current" Axes for you. The object-oriented interface ( ax.plot ) makes that Axes explicit.
What you'll see: two windows, one after the other, each showing the same upward parabola. The only difference is the code style — plt.title versus ax.set_title — proving the two interfaces produce identical results.
You control how big the canvas is with figsize=(width, height) in inches, and you can give the whole Figure a heading with fig.suptitle() .
What you'll see: a noticeably wider-than-tall chart with a bold "Monthly Visitors" heading across the very top of the Figure, sitting above the plotted line.
Replace each ___ to build a Figure and Axes and draw on it.
❌ AttributeError: 'Axes' object has no attribute 'title'
On an Axes use ax.set_title("...") , not ax.title("...") . The plain title form belongs to plt .
Each plt.show() displays and then clears the current figure. Build a fresh fig, ax for the next chart.
Build a wide Figure with one Axes, plot some data, and add a figure-wide title.
Lesson 2 complete — you understand the canvas!
You learned that a Figure holds Axes, met plt.subplots() , and saw the difference between the pyplot and object-oriented interfaces.
🚀 Up next: Your First Line Plot — plot multiple series and shape real data into lines.
Practice quiz
In Matplotlib, what is the Figure?
- A single plot area with one x and y axis
- The whole canvas that holds everything
- A line drawn on a chart
- The colormap
Answer: The whole canvas that holds everything. The Figure is the overall container; an Axes is a single plot area inside it.
What is an Axes?
- The whole window
- A single plot area with its own x and y axis
- A list of tick labels
- The figure title
Answer: A single plot area with its own x and y axis. An Axes is one plot region with its own data, x-axis, and y-axis.
What does fig, ax = plt.subplots() return?
- Two Axes
- Two Figures
- A Figure and an Axes
- A Figure and a colorbar
Answer: A Figure and an Axes. plt.subplots() creates a Figure and (by default) a single Axes and returns both.
How many Axes can one Figure contain?
- Exactly one
- At most two
- Many (a grid of subplots)
- Zero
Answer: Many (a grid of subplots). One Figure can hold one Axes or a whole grid of them.
Which call sets the figure size to 8 by 4 inches?
- plt.subplots(size=8x4)
- plt.subplots(figsize=(8, 4))
- plt.subplots(dpi=(8, 4))
- plt.subplots(inches=8, 4)
Answer: plt.subplots(figsize=(8, 4)). figsize=(width, height) in inches sets the canvas size; width comes first.
Which method titles a single Axes?
- ax.set_title()
- fig.suptitle()
- ax.title()
- plt.figtitle()
Answer: ax.set_title(). ax.set_title() titles one Axes; fig.suptitle() titles the whole Figure.
Which method adds a title across the entire Figure?
- ax.set_title()
- ax.suptitle()
- fig.suptitle()
- plt.axtitle()
Answer: fig.suptitle(). fig.suptitle() places a heading over the whole Figure.
The pyplot interface (plt.plot) is best described as...
- The object-oriented interface
- A state-machine that tracks the current Axes
- A 3D plotting mode
- An animation tool
Answer: A state-machine that tracks the current Axes. plt.plot uses the pyplot state machine, drawing on the implicit current Axes.
Which style scales best to complex, multi-subplot figures?
- The implicit plt.plot style
- The object-oriented ax.plot style
- Neither works for subplots
- Only plt.show()
Answer: The object-oriented ax.plot style. The explicit object-oriented (fig, ax) style scales better as figures grow complex.
In figsize=(8, 4), which dimension comes first?
- Height
- Width
- DPI
- Aspect ratio
Answer: Width. figsize is (width, height) in inches, so width always comes first.