A blank canvas with coordinates.
Create an explicit Figure and Axes, then save your first real chart.
01 The idea
A Figure is the complete canvas; an Axes is a plotting region inside it. Using fig, ax = plt.subplots() makes that ownership explicit and scales well when a report contains several panels. This course saves charts with the noninteractive Agg backend so the scripts work in terminals and headless environments. Open the resulting PNG to inspect it; interactive notebooks can also display figures directly.
02 The experiment
Read it once. Predict what will happen. Then copy it into a .py file and run it in your local Python setup.
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 3.5), layout="constrained")
ax.plot([1, 2, 3], [2, 5, 4], marker="o", color="#ed5027")
ax.set(title="A first signal", xlabel="Experiment", ylabel="Score")
ax.grid(axis="y", alpha=0.2)
fig.savefig("matplotlib-first-figure.png", dpi=140, bbox_inches="tight")
plt.close(fig)
print("Saved matplotlib-first-figure.png")Saved matplotlib-first-figure.png

03 Under the hood
- 1
Install the workbench requirements first. Agg is selected before importing pyplot; backend selection controls rendering rather than the meaning of the data.
- 2
plot receives corresponding x and y values. The marker makes the three observations visible, while the line suggests their sequence.
- 3
Save through fig.savefig, then close the figure to release resources in a batch job. A chart should have units, labels, and enough context for someone who never saw your code.
04 Your turn, builder
Create a four-point chart of completed tasks across four days and label both axes.
Reveal one possible solution +
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 3.5), layout="constrained")
ax.plot([1, 2, 3, 4], [2, 4, 3, 6], marker="o", color="#ed5027")
ax.set(xlabel="Day", ylabel="Completed tasks", title="Daily progress")
fig.savefig("challenge.png", dpi=140, bbox_inches="tight")
plt.close(fig)
print("Saved challenge.png")05 Check your signal
What is an Axes?
Experiment. Logged.
When you can explain the idea and make the example your own, mark it complete. Your log stays in this browser.
Keep exploring
Go deeper with the official Python guide ↗.