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

2023

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

  1. A.

    To add a title to a plot

  2. B.

    To add annotations to a plot

  3. C.

    To label different lines or markers on a plot

  4. D.

    To label the x and y axes of a plot

Attempted by 1544 students.

Show answer & explanation

Correct answer: C

The legend() function displays a legend box that identifies different plotted lines or markers using their labels.

Explore the full course: Bpsc