O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Specifying the legend content and position

To change the text used for each data series in the legend (the default is the column name from DataFrame), capture the ax object returned from the .plot() method and use its .legend() method. This object is an AxesSubplot object and can be used to change various aspects of the plot before it is generated:

The location of the legend can be set using the loc parameter of .legend(). By default, pandas sets the location to 'best', which tells matplotlib to examine the data and determine the best place it thinks to put the legend. However, you can also specify any of the following to position the legend ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required