@@ -368,6 +368,7 @@ def __init__(self, parent, handles, labels,
368
368
bbox_transform = None , # transform for the bbox
369
369
frameon = None , # draw frame
370
370
handler_map = None ,
371
+ outside = False ,
371
372
):
372
373
"""
373
374
Parameters
@@ -425,6 +426,7 @@ def __init__(self, parent, handles, labels,
425
426
self .legendHandles = []
426
427
self ._legend_title_box = None
427
428
429
+ self .outside = outside
428
430
#: A dictionary with the extra handler mappings for this Legend
429
431
#: instance.
430
432
self ._custom_handler_map = handler_map
@@ -1106,8 +1108,37 @@ def _get_anchored_bbox(self, loc, bbox, parentbbox, renderer):
1106
1108
c = anchor_coefs [loc ]
1107
1109
1108
1110
fontsize = renderer .points_to_pixels (self ._fontsize )
1109
- container = parentbbox .padded (- (self .borderaxespad ) * fontsize )
1110
- anchored_box = bbox .anchored (c , container = container )
1111
+ if not self .outside :
1112
+ container = parentbbox .padded (- (self .borderaxespad ) * fontsize )
1113
+ anchored_box = bbox .anchored (c , container = container )
1114
+ else :
1115
+ if c in ['NE' , 'SE' , 'E' ]:
1116
+ stack = 'right'
1117
+ elif c in ['NW' , 'SW' , 'W' ]:
1118
+ stack = 'left'
1119
+ elif c in ['N' ]:
1120
+ stack = 'top'
1121
+ else :
1122
+ stack = 'bottom'
1123
+ if self .outside == 'vertical' :
1124
+ if c in ['NE' , 'NW' ]:
1125
+ stack = 'top'
1126
+ elif c in ['SE' , 'SW' ]:
1127
+ stack = 'bottom'
1128
+ anchored_box = bbox .anchored (c , container = parentbbox )
1129
+ if stack == 'right' :
1130
+ anchored_box .x0 = (anchored_box .x0 + anchored_box .width +
1131
+ (self .borderaxespad ) * fontsize )
1132
+ elif stack == 'left' :
1133
+ anchored_box .x0 = (anchored_box .x0 - anchored_b
890E
ox .width -
1134
+ (self .borderaxespad ) * fontsize )
1135
+ elif stack == 'bottom' :
1136
+ anchored_box .y0 = (anchored_box .y0 - anchored_box .height -
1137
+ (self .borderaxespad ) * fontsize )
1138
+ elif stack == 'top' :
1139
+ anchored_box .y0 = (anchored_box .y0 + anchored_box .height +
1140
+ (self .borderaxespad ) * fontsize )
1141
+
1111
1142
return anchored_box .x0 , anchored_box .y0
1112
1143
1113
1144
def _find_best_position (self , width , height , renderer , consider = None ):
0 commit comments