Position Matplotlib Legends

We can easily position legends in Matplotlib using the loc parameter of the legend() method. The following values set position:

  • ‘upper left’, ‘upper right’, ‘lower left’, ‘lower right’
  • ‘upper center’, ‘lower center’, ‘center left’, ‘center right’
  • ‘center’

Here is what we have listed above:

  • The strings ‘upper left’, ‘upper right’, ‘lower left’, ‘lower right’ places the legend at the corresponding corner of the axes/figure.
  • The strings ‘upper center’, ‘lower center’, ‘center left’, ‘center right’ place the legend at the center of the corresponding edge of the axes/figure.
  • The string ‘center’ places the legend at the center of the axes/figure.

Let us now see an example to create a graph in Matplotlib, set legends and its position as well:


Position Matplotlib Legends

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.

For Videos, Join Our YouTube Channel: Join Now

Add a Matplotlib Legend in a Graph
Change the background color of the Matplotlib legend
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading