Skip to main contentSkip to solution

What does plt.legend( ) function do?

Solution

✅ Correct Option: 2

In Matplotlib, plt.legend() displays a legend, a box that identifies each plotted line or marker using the label given in the plotting call, for example plt.plot(x, y, label="Sales").


Option 1: axis labels are added with plt.xlabel() and plt.ylabel().

Option 3: the title is added with plt.title().

plt.legend() shows only the lines that have a label, so without labels the legend is empty.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question