Adding Titles, Labels, and Legends
After styling your plot, the next step is to communicate meaning clearly through labels.
Titles and axis labels help readers understand what they’re looking at, while legends make it easy to distinguish between multiple data series.
In this lesson, you’ll learn how to add a chart title, axis labels, and a legend using simple Matplotlib functions.
Title
Use plt.title() to add a heading to your chart.
plt.title("Monthly Revenue")
Axis Labels
Use plt.xlabel() and plt.ylabel() to label the x-axis and y-axis.
plt.xlabel("Month") plt.ylabel("Revenue ($)")
These labels help the reader understand what the axes represent.
Legends
If you plot more than one line, use label= inside plt.plot() and call plt.legend() to display a legend.
plt.plot(x, y1, label="Product A") plt.plot(x, y2, label="Product B") plt.legend()
The legend automatically matches each line to its label, making multi-line charts easier to interpret at a glance.
How can you add a legend to a Matplotlib plot with multiple lines?
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help