1. Home
  2. Data Science
  3. Matplotlib
  4. What is the purpose of the plt.legend() function in…

Added 24 Feb 2024

What is the purpose of the plt.legend() function in Matplotlib?

  1. To set the plot legend Correct answer
  2. To create subplots
  3. To adjust the plot size
  4. To display the plot

Correct answer

A. To set the plot legend

17 views

MCQSEXAM

Explanation

plt.legend() adds a legend to the plot, identifying each line or series by the label given when it was plotted. The loc argument controls its position.

Without labels on the plotted series, the legend has nothing to show.

For more solved questions like this one, see Data Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Matplotlib MCQs

Practise all Matplotlib MCQs

Similar MCQs