Adding a Legend to the Plot

In this lesson, we will learn how to add a legend to the plot.

What is a legend?

A legend provides a description for an element in the figure. A legend helps the user understand a figure when the figure contains many elements. For example, if there are two curves on a graph, then the legend can help the user distinguish between the curves.

There is more than one way to add a legend to a figure. In this lesson, we will learn two methods. Both use the plot() function. The difference, however, is in how the two methods set their labels.

Adding a legend without labels

In this method, we don’t pass the labels to the legend(), because the labels are passed in plot(). When legend() is called, the Axes would detect the labels ...

Access this course and 1400+ top-rated courses and projects.