Legends
We have seen that when we have multiple columns plotted on the same plot, pandas automatically provides us with a legend by default. If we don't like the location of the legend, we can use plt.legend() to move it to a better location; when working with Axes objects, we also have the legend() method, which will work on the subplot. This can also be used to show a legend when the figure doesn't have one initially, but after the addition of reference lines, one is required for clarity.
The legend will use the label of each object that was plotted. If we don't want something to show up, we can make its label an empty string. However, if we simply want to alter how something shows up, we can pass its display name through the label argument. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access