@@ -1087,6 +1087,16 @@ def legend(self, *args, **kwargs):
10871087 ----------------
10881088 %(_legend_kw_doc)s
10891089
1090+ If a figure is using the constrained layout manager, the string codes
1091+ of the *loc* keyword argument can get better layout behaviour using the
1092+ prefix 'outside'. There is ambiguity at the corners, so 'outside
1093+ upper right' will make space for the legend above the rest of the
1094+ axes in the layout, and 'outside right upper' will make space on the
1095+ right side of the layout. In addition to the values of *loc*
1096+ listed above, we have 'outside right upper', 'outside right lower',
1097+ 'outside left upper', and 'outside left lower'. See
1098+ :doc:`/tutorials/intermediate/legend_guide` for more details.
1099+
10901100 See Also
10911101 --------
10921102 .Axes.legend
@@ -1113,32 +1123,9 @@ def legend(self, *args, **kwargs):
11131123 # extra_args = extra_args[1:]
11141124 pass
11151125 transform = kwargs .pop ('bbox_transform' , self .transSubfigure )
1116- outside = None
1117- if 'loc' in kwargs :
1118- # need to protect this in case loc was passed in
1119- # positionally...
1120- loc = kwargs .pop ('loc' , None )
1121- # handle outside legends:
1122- if isinstance (loc , str ):
1123- if loc .split ()[0 ] == 'outside' :
1124- # strip outside:
1125- loc = loc .split ('outside ' )[1 ]
1126- # strip "center" at the beginning
1127- outside = loc .replace ('center ' , '' )
1128- # strip first
1129- outside = outside .split ()[0 ]
1130- locs = loc .split ()
1131- if len (locs ) > 1 and locs [0 ] in ('right' , 'left' ):
1132- # locs doesn't accept "left upper", etc, so swap
1133- if locs [0 ] != 'center' :
1134- locs = locs [::- 1 ]
1135- loc = locs [0 ] + ' ' + locs [1 ]
1136-
1137- kwargs ['loc' ] = loc
11381126 # explicitly set the bbox transform if the user hasn't.
11391127 l = mlegend .Legend (self , handles , labels , * extra_args ,
11401128 bbox_transform = transform , ** kwargs )
1141- l ._outside = outside
11421129 self .legends .append (l )
11431130 l ._remove_method = self .legends .remove
11441131 self .stale = True
0 commit comments