Recall & Review
beginner
What is the purpose of a legend in a matplotlib plot?
A legend explains what different colors, lines, or markers in the plot represent. It helps the viewer understand the data easily.
Click to reveal answer
intermediate
How do you place a legend outside the plot area in matplotlib?
Use the
loc parameter with values like 'upper left' and the bbox_to_anchor parameter to position the legend outside the plot. For example, plt.legend(loc='upper left', bbox_to_anchor=(1, 1)) places it to the right outside the plot.Click to reveal answer
beginner
What does the
frameon parameter do in matplotlib legends?The
frameon parameter controls whether the legend has a border box around it. Setting frameon=False removes the box, making the legend look cleaner.Click to reveal answer
beginner
How can you change the font size of legend text in matplotlib?
Use the
fontsize parameter inside plt.legend(). For example, plt.legend(fontsize='small') or plt.legend(fontsize=12) changes the text size.Click to reveal answer
intermediate
What is the effect of the
ncol parameter in matplotlib legends?The
ncol parameter sets how many columns the legend entries are arranged into. For example, ncol=2 arranges legend items in two columns, which can save vertical space.Click to reveal answer
Which parameter controls the position of the legend inside or outside the plot area?
✗ Incorrect
The
loc parameter sets the legend's position, such as 'upper right' or 'lower left'.How do you remove the border box around a legend in matplotlib?
✗ Incorrect
Setting
frameon=False removes the border box around the legend.What does
bbox_to_anchor=(1,1) do when used with loc='upper left'?✗ Incorrect
It places the legend outside the plot area to the right, aligned at the top.
Which parameter changes the number of columns in a legend?
✗ Incorrect
The
ncol parameter sets how many columns the legend uses.How can you make legend text smaller in matplotlib?
✗ Incorrect
Using
fontsize='small' or a smaller numeric value reduces the legend text size.Explain how to place a legend outside the plot area and style it with no border and smaller font.
Think about loc, bbox_to_anchor, frameon, and fontsize parameters.
You got /3 concepts.
Describe how to arrange legend items in two columns and why you might want to do that.
Focus on legend layout and space management.
You got /3 concepts.