@@ -1087,6 +1087,16 @@ def legend(self, *args, **kwargs):
1087
1087
----------------
1088
1088
%(_legend_kw_doc)s
1089
1089
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
+
1090
1100
See Also
1091
1101
--------
1092
1102
.Axes.legend
@@ -1113,32 +1123,9 @@ def legend(self, *args, **kwargs):
1113
1123
# extra_args = extra_args[1:]
1114
1124
pass
1115
1125
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
1138
1126
# explicitly set the bbox transform if the user hasn't.
1139
1127
l = mlegend .Legend (self , handles , labels , * extra_args ,
1140
1128
bbox_transform = transform , ** kwargs )
1141
- l ._outside = outside
1142
1129
self .legends .append (l )
1143
1130
l ._remove_method = self .legends .remove
1144
1131
self .stale = True
0 commit comments