What is Matplotlib?
Matplotlib is the core plotting library in Python.
- Flexible and powerful
- Works everywhere (scripts, notebooks)
- Backbone for many libraries (including Seaborn)
Matplotlib was started by John Hunter in 2002 to bring a MATLAB-like plotting interface to Python. It can export charts to almost every common format — PNG, SVG, PDF, and more — which is why it's still the default choice for publication-quality figures, even with newer libraries around.
How a plot gets built
flowchart LR A["Your data"] --> B["Figure (the canvas)"] B --> C["Axes (one plotting area)"] C --> D["Artists (lines, bars, ticks, text)"] E["plt.plot() - quick pyplot API"] -.-> C F["fig, ax = plt.subplots() - OO API"] -.-> C
Two common ways to plot
1) Pyplot (quick)
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [3, 2, 5])
plt.title("Quick plot")
plt.show()2) Object-oriented API (recommended)
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot([1, 2, 3], [3, 2, 5])
ax.set_title("OO plot")
ax.set_xlabel("x")
ax.set_ylabel("y")
plt.show()Key terms
- Figure: the whole canvas
- Axes: the plotting area
- Artist: everything drawn on the figure
In this phase, we’ll focus on practical charts you need for analytics.
Check your understanding
Which approach does the lesson recommend for building plots?
Pyplot is quick, but the object-oriented API is recommended because it is more consistent and reusable.
Show answer
A — The object-oriented API with fig, ax = plt.subplots() — Pyplot is quick, but the object-oriented API is recommended because it is more consistent and reusable.
In Matplotlib terms, what is an Axes?
The Figure is the whole canvas, the Axes is the plotting area, and an Artist is everything drawn on the figure.
Show answer
A — The plotting area — The Figure is the whole canvas, the Axes is the plotting area, and an Artist is everything drawn on the figure.
Which statement about Matplotlib is true?
Matplotlib started in 2002 and exports to almost every common format, which is why it suits publication-quality figures.
Show answer
A — It can export PNG, SVG, PDF and more, and it is the backbone for libraries such as Seaborn — Matplotlib started in 2002 and exports to almost every common format, which is why it suits publication-quality figures.
Which call actually displays the figure in a script?
The examples end with plt.show(), which renders the chart you built.
Show answer
A — plt.show() — The examples end with plt.show(), which renders the chart you built.
Next
Continue to Anatomy of a Plot to see exactly how Figure, Axes, ticks, and labels fit together.
🧪 Try It Yourself
Exercise 1 – Object-oriented basics
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Labelling an Axes
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – A grid of Axes
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.