@@ -137,7 +137,7 @@ def get_rotation(rotation):
137
137
# function as a method with some refactoring of _get_layout method.
138
138
139
139
140
- def _get_textbox (text , renderer ):
140
+ def _get_textbox (text , renderer , with_descent = True ):
141
141
"""
142
142
Calculate the bounding box of the text. Unlike
143
143
:meth:`matplotlib.text.Text.get_extents` method, The bbox size of
@@ -165,6 +165,10 @@ def _get_textbox(text, renderer):
165
165
xt_box , yt_box = min (projected_xs ), min (projected_ys )
166
166
w_box , h_box = max (projected_xs ) - xt_box , max (projected_ys ) - yt_box
167
167
168
+ if not with_descent :
169
+ yt_box += d
170
+ h_box -= d
171
+
168
172
tr = mtransforms .Affine2D ().rotate (theta )
169
173
170
174
x_box , y_box = tr .transform_point ((xt_box , yt_box ))
@@ -232,7 +236,6 @@ def __init__(self,
232
236
self ._linespacing = linespacing
233
237
self .set_rotation_mode (rotation_mode )
234
238
self .update (kwargs )
235
- # self.set_bbox(dict(pad=0))
236
239
237
240
def __getstate__ (self ):
238
241
d = super (Text , self ).__getstate__ ()
@@ -481,10 +484,13 @@ def set_bbox(self, rectprops):
481
484
482
485
if rectprops is not None :
483
486
props = rectprops .copy ()
484
- # Dump the pad kwarg; we still need to figure out how to
485
- # use it to expand the box, for backwards compatibility.
486
- pad = props .pop ('pad' , 4 ) # noqa
487
+ pad = props .pop ('pad' , 4 ) # in points; hardwired default
487
488
boxstyle = props .pop ("boxstyle" , "square" )
489
+ # If pad is in the boxstyle string, it will be passed
490
+ # directly to the FancyBboxPatch as font units.
491
+ if 'pad' not in boxstyle :
492
+ boxstyle += ",pad=%0.2f" % (pad / self .get_size ())
493
+
488
494
bbox_transmuter = props .pop ("bbox_transmuter" , None )
489
495
490
496
self ._bbox_patch = FancyBboxPatch (
@@ -524,7 +530,8 @@ def update_bbox_position_size(self, renderer):
524
530
525
531
posx , posy = trans .transform_point ((posx , posy ))
526
532
527
- x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
533
+ x_box , y_box , w_box , h_box = _get_textbox (self , renderer ,
534
+ with_descent = False )
528
535
self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
529
536
theta = np .deg2rad (self .get_rotation ())
530
537
tr = mtransforms .Affine2D ().rotate (theta )
@@ -540,7 +547,8 @@ def _draw_bbox(self, renderer, posx, posy):
540
547
(FancyBboxPatch), and draw
541
548
"""
542
549
543
- x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
550
+ x_box , y_box , w_box , h_box = _get_textbox (self , renderer ,
551
+ with_descent = False )
544
552
self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
545
553
theta = np .deg2rad (self .get_rotation ())
546
554
tr = mtransforms .Affine2D ().rotate (theta )
0 commit comments