@@ -112,23 +112,24 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
112112_legend_kw_doc = '''
113113loc : int or string or pair of floats, default: :rc:`legend.loc` ('best' for \
114114 axes, 'upper right' for figures)
115- The location of the legend. Possible codes are:
116-
117- =============== =============
118- Location String Location Code
119- =============== =============
120- 'best' 0
121- 'upper right' 1
122- 'upper left' 2
123- 'lower left' 3
124- 'lower right' 4
125- 'right' 5
126- 'center left' 6
127- 'center right' 7
128- 'lower center' 8
129- 'upper center' 9
130- 'center' 10
131- =============== =============
115+ The location of the legend.
116+ Possible (case-insensitive) strings and codes are:
117+
118+ =============== ============== =============
119+ Location String Compass String Location Code
120+ =============== ============== =============
121+ 'best' 0
122+ 'upper right' 'NE' 1
123+ 'upper left' 'NW' 2
124+ 'lower left' 'SW' 3
125+ 'lower right' 'SE' 4
126+ 'right' 5
127+ 'center left' 'W' 6
128+ 'center right' 'E' 7
129+ 'lower center' 'S' 8
130+ 'upper center' 'N' 9
131+ 'center' 'C' 10
132+ =============== ============== =============
132133
133134
134135 Alternatively can be a 2-tuple giving ``x, y`` of the lower-left
@@ -320,7 +321,9 @@ class Legend(Artist):
320321 'upper center' : 9 ,
321322 'center' : 10 ,
322323 }
323-
324+ compasscodes = {'nw' : 2 , 'n' : 9 , 'ne' : 1 , 'w' : 6 , 'c' : 10 , 'e' : 7 ,
325+ 'sw' : 3 , 's' : 8 , 'se' : 4 })
326+ allcodes = {** codes , ** compasscodes }
324327 zorder = 5
325328
326329 def __str__ (self ):
@@ -489,23 +492,23 @@ def __init__(self, parent, handles, labels,
489492 if not self .isaxes and loc in [0 , 'best' ]:
490493 loc = 'upper right'
491494 if isinstance (loc , str ):
492- if loc not in self .codes :
495+ if loc . lower () not in self .allcodes :
493496 if self .isaxes :
494497 cbook .warn_deprecated (
495498 "3.1" , message = "Unrecognized location {!r}. Falling "
496499 "back on 'best'; valid locations are\n \t {}\n "
497500 "This will raise an exception %(removal)s."
498- .format (loc , '\n \t ' .join (self .codes )))
501+ .format (loc , '\n \t ' .join (self .allcodes )))
499502 loc = 0
500503 else :
501504 cbook .warn_deprecated (
502505 "3.1" , message = "Unrecognized location {!r}. Falling "
503506 "back on 'upper right'; valid locations are\n \t {}\n '"
504507 "This will raise an exception %(removal)s."
505- .format (loc , '\n \t ' .join (self .codes )))
508+ .format (loc , '\n \t ' .join (self .allcodes )))
506509 loc = 1
507510 else :
508- loc = self .codes [loc ]
511+ loc = self .allcodes [loc . lower () ]
509512 if not self .isaxes and loc == 0 :
510513 cbook .warn_deprecated (
511514 "3.1" , message = "Automatic legend placement (loc='best') not "
0 commit comments