@@ -112,23 +112,24 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
112
112
_legend_kw_doc = '''
113
113
loc : int or string or pair of floats, default: :rc:`legend.loc` ('best' for \
114
114
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
+ =============== ============== =============
132
133
133
134
134
135
Alternatively can be a 2-tuple giving ``x, y`` of the lower-left
@@ -320,7 +321,9 @@ class Legend(Artist):
320
321
'upper center' : 9 ,
321
322
'center' : 10 ,
322
323
}
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 }
324
327
zorder = 5
325
328
326
329
def __str__ (self ):
@@ -489,23 +492,23 @@ def __init__(self, parent, handles, labels,
489
492
if not self .isaxes and loc in [0 , 'best' ]:
490
493
loc = 'upper right'
491
494
if isinstance (loc , str ):
492
- if loc not in self .codes :
495
+ if loc . lower () not in self .allcodes :
493
496
if self .isaxes :
494
497
cbook .warn_deprecated (
495
498
"3.1" , message = "Unrecognized location {!r}. Falling "
496
499
"back on 'best'; valid locations are\n \t {}\n "
497
500
"This will raise an exception %(removal)s."
498
- .format (loc , '\n \t ' .join (self .codes )))
501
+ .format (loc , '\n \t ' .join (self .allcodes )))
499
502
loc = 0
500
503
else :
501
504
cbook .warn_deprecated (
502
505
"3.1" , message = "Unrecognized location {!r}. Falling "
503
506
"back on 'upper right'; valid locations are\n \t {}\n '"
504
507
"This will raise an exception %(removal)s."
505
- .format (loc , '\n \t ' .join (self .codes )))
508
+ .format (loc , '\n \t ' .join (self .allcodes )))
506
509
loc = 1
507
510
else :
508
- loc = self .codes [loc ]
511
+ loc = self .allcodes [loc . lower () ]
509
512
if not self .isaxes and loc == 0 :
510
513
cbook .warn_deprecated (
511
514
"3.1" , message = "Automatic legend placement (loc='best') not "
0 commit comments