Skip to content

geographic directions added as alternative locations in legend #16820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
The location of the legend.

The strings
``'upper left', 'upper right', 'lower left', 'lower right'``
``'upper left', 'upper right', 'lower left', 'lower right',
'northwest', 'northeast', 'southwest', 'southeast'``
place the legend at the corresponding corner of the axes/figure.

The strings
``'upper center', 'lower center', 'center left', 'center right'``
``'upper center', 'lower center', 'center left', 'center right',
'north', 'south', 'west', 'east'``
place the legend at the center of the corresponding edge of the
axes/figure.

Expand All @@ -120,21 +122,21 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
be spelled ``'right'``, and each "string" locations can also be given as a
numeric value:

=============== =============
Location String Location Code
=============== =============
'best' 0
'upper right' 1
'upper left' 2
'lower left' 3
'lower right' 4
'right' 5
'center left' 6
'center right' 7
'lower center' 8
'upper center' 9
'center' 10
=============== =============
========================== =============
Location String Location Code
========================== =============
'best' 0
'upper right', 'northeast' 1
'upper left', 'northwest' 2
'lower left', 'southwest' 3
'lower right', 'southeast' 4
'right' 5
'center left', 'west' 6
'center right', 'east' 7
'lower center', 'south' 8
'upper center', 'north' 9
'center' 10
========================== =============

bbox_to_anchor : `.BboxBase`, 2-tuple, or 4-tuple of floats
Box that is used to position the legend in conjunction with *loc*.
Expand Down Expand Up @@ -266,14 +268,22 @@ class Legend(Artist):
"""
codes = {'best': 0, # only implemented for axes legends
'upper right': 1,
'northeast': 1,
'upper left': 2,
'northwest': 2,
'lower left': 3,
'southwest': 3,
'lower right': 4,
'southeast': 4,
'right': 5,
'center left': 6,
'west': 6,
'center right': 7,
'east': 7,
'lower center': 8,
'south': 8,
'upper center': 9,
'north': 9,
'center': 10,
}

Expand Down