@@ -946,8 +946,10 @@ 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
950
- Padding between the offsetbox frame and the *bbox_to_anchor*.
949
+ borderpad : float or tuple[float, float], default: 0.5
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.
951
953
child : `.OffsetBox`
952
954
The box that will be anchored.
953
955
prop : `.FontProperties`
@@ -1052,14 +1054,29 @@ def set_bbox_to_anchor(self, bbox, transform=None):
1052
1054
self .stale = True
1053
1055
1054
1056
@_compat_get_offset
1057
+
1055
1058
def get_offset (self , bbox , renderer ):
1056
- # docstring inherited
1057
- pad = (self .borderpad
1058
- * renderer .points_to_pixels (self .prop .get_size_in_points ()))
1059
+ fontsize_in_pixels = renderer .points_to_pixels (self .prop .get_size_in_points ())
1060
+ try :
1061
+ borderpad_x , borderpad_y = self .borderpad
1062
+ except (TypeError , ValueError ):
1063
+ borderpad_x = self .borderpad
1064
+ borderpad_y = self .borderpad
1065
+ pad_x_pixels = borderpad_x * fontsize_in_pixels
1066
+ pad_y_pixels = borderpad_y * fontsize_in_pixels
1059
1067
bbox_to_anchor = self .get_bbox_to_anchor ()
1068
+ padded_bbox_to_anchor = Bbox .from_extents (
1069
+ bbox_to_anchor .x0 + pad_x_pixels ,
1070
+ bbox_to_anchor .y0 + pad_y_pixels ,
1071
+ bbox_to_anchor .x1 - pad_x_pixels ,
1072
+ bbox_to_anchor .y1 - pad_y_pixels
1073
+ )
1060
1074
x0 , y0 = _get_anchored_bbox (
1061
- self .loc , Bbox .from_bounds (0 , 0 , bbox .width , bbox .height ),
1062
- bbox_to_anchor , pad )
1075
+ self .loc ,
1076
+ Bbox .from_bounds (0 , 0 , bbox .width , bbox .height ),
1077
+ padded_bbox_to_anchor ,
1078
+ 0
1079
+ )
1063
1080
return x0 - bbox .x0 , y0 - bbox .y0
1064
1081
1065
1082
def update_frame (self , bbox , fontsize = None ):
0 commit comments