@@ -946,8 +946,13 @@ def __init__(self, loc, *,
946
946
See the parameter *loc* of `.Legend` for details.
947
947
pad : float, default: 0.4
948
948
Padding around the child as fraction of the fontsize.
949
- borderpad : float, default: 0.5
949
+ borderpad : float or (float, float) , default: 0.5
950
950
Padding between the offsetbox frame and the *bbox_to_anchor*.
951
+ If a float, the same padding is used for both x and y.
952
+ If a tuple of two floats, it specifies the (x, y) padding.
953
+
954
+ .. versionadded:: 3.11
955
+ The *borderpad* parameter now accepts a tuple of (x, y) paddings.
951
956
child : `.OffsetBox`
952
957
The box that will be anchored.
953
958
prop : `.FontProperties`
@@ -1054,12 +1059,22 @@ def set_bbox_to_anchor(self, bbox, transform=None):
1054
1059
@_compat_get_offset
1055
1060
def get_offset (self , bbox , renderer ):
1056
1061
# docstring inherited
1057
- pad = (self .borderpad
1058
- * renderer .points_to_pixels (self .prop .get_size_in_points ()))
1062
+ fontsize_in_pixels = renderer .points_to_pixels (self .prop .get_size_in_points ())
1063
+ try :
1064
+ borderpad_x , borderpad_y = self .borderpad
1065
+ except TypeError :
1066
+ borderpad_x = self .borderpad
1067
+ borderpad_y = self .borderpad
1068
+ pad_x_pixels = borderpad_x * fontsize_in_pixels
1069
+ pad_y_pixels = borderpad_y * fontsize_in_pixels
1059
1070
bbox_to_anchor = self .get_bbox_to_anchor ()
1060
1071
x0 , y0 = _get_anchored_bbox (
1061
- self .loc , Bbox .from_bounds (0 , 0 , bbox .width , bbox .height ),
1062
- bbox_to_anchor , pad )
1072
+ self .loc ,
1073
+ Bbox .from_bounds (0 , 0 , bbox .width , bbox .height ),
1074
+ bbox_to_anchor ,
1075
+ pad_x_pixels ,
1076
+ pad_y_pixels
1077
+ )
1063
1078
return x0 - bbox .x0 , y0 - bbox .y0
1064
1079
1065
1080
def update_frame (self , bbox , fontsize = None ):
@@ -1084,15 +1099,15 @@ def draw(self, renderer):
1084
1099
self .stale = False
1085
1100
1086
1101
1087
- def _get_anchored_bbox (loc , bbox , parentbbox , borderpad ):
1102
+ def _get_anchored_bbox (loc , bbox , parentbbox , pad_x , pad_y ):
1088
1103
"""
1089
1104
Return the (x, y) position of the *bbox* anchored at the *parentbbox* with
1090
- the *loc* code with the *borderpad*.
1105
+ the *loc* code with the *borderpad* and padding *pad_x*, *pad_y* .
1091
1106
"""
1092
1107
# This is only called internally and *loc* should already have been
1093
1108
# validated. If 0 (None), we just let ``bbox.anchored`` raise.
1094
1109
c = [None , "NE" , "NW" , "SW" , "SE" , "E" , "W" , "E" , "S" , "N" , "C" ][loc ]
1095
- container = parentbbox .padded (- borderpad )
1110
+ container = parentbbox .padded (- pad_x , - pad_y )
1096
1111
return bbox .anchored (c , container = container ).p0
1097
1112
1098
1113
0 commit comments