From the course: NumPy Essential Training: 2 MatPlotlib and Linear Algebra Capabilities

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Understanding legends

Understanding legends

- [Instructor] We have already learned how to label our plots using axis labels and titles. In the case, when we want to show multiple graphs between a single axis, it's extremely helpful to create a plot legend that labels each line type. The legend is the description of each of the graphs on given axis. "Matplotlib" has a built-in function to create a legend called "plt.legend". There are few ways to use it. We'll explore the most useful ones. We have already imported 'numpy' as NP and 'matplotlib.pyplot' as plt. Now we are going to define X using the lean space function and create a linear graph and call it first line, and define Y as Y = X + 1. Next, we are going to specify a label as a part of the line plot and code the legend function. Let's run our code. As you can see we have plotted the graph using an inline label. The next way to specify a label is by using the set label function. Let's create two linear…

Contents