Recall & Review
beginner
What is the purpose of having multiple legends in a matplotlib plot?
Multiple legends help to clearly explain different groups or types of data in the same plot, making it easier to understand complex visuals.
Click to reveal answer
intermediate
How do you create a second legend in matplotlib after the first one?
You create the first legend normally, then save its reference. For the second legend, you use
ax.legend() again with different handles and labels, and add it to the axes with ax.add_artist().Click to reveal answer
intermediate
What does
ax.add_artist() do in the context of multiple legends?It adds the second legend as an artist to the axes, so both legends can appear on the same plot without replacing each other.
Click to reveal answer
beginner
Why might you want to use multiple legends instead of combining all labels into one legend?
Multiple legends allow grouping related items separately, improving clarity when different data types or categories need distinct explanations.
Click to reveal answer
beginner
Which matplotlib object typically holds the legend in a plot?
The legend is an artist object attached to the axes, often returned by
ax.legend().Click to reveal answer
What function do you call to create a legend in matplotlib?
✗ Incorrect
The
ax.legend() function creates a legend for the plot.How do you add a second legend to a matplotlib plot without removing the first?
✗ Incorrect
You create the first legend normally, then add the second legend as an artist with
ax.add_artist().What does the
handles parameter in ax.legend(handles=...) specify?✗ Incorrect
The
handles parameter tells matplotlib which plot elements to show in the legend.Why is it important to use
ax.add_artist() when adding a second legend?✗ Incorrect
ax.add_artist() adds the second legend without replacing the first.Which of these is NOT a reason to use multiple legends?
✗ Incorrect
Multiple legends are used to clarify, not confuse, the plot.
Explain how to add multiple legends to a matplotlib plot and why it might be useful.
Think about how to keep both legends visible and why separate explanations help.
You got /5 concepts.
Describe the role of the handles and labels parameters when creating legends in matplotlib.
Handles and labels work together to define legend content.
You got /4 concepts.