@@ -118,7 +118,7 @@ def get_rotation(rotation):
118
118
# function as a method with some refactoring of _get_layout method.
119
119
120
120
121
- def _get_textbox (text , renderer ):
121
+ def _get_textbox (text , renderer , with_descent = True ):
122
122
"""
123
123
Calculate the bounding box of the text. Unlike
124
124
:meth:`matplotlib.text.Text.get_extents` method, The bbox size of
@@ -146,6 +146,10 @@ def _get_textbox(text, renderer):
146
146
xt_box , yt_box = min (projected_xs ), min (projected_ys )
147
147
w_box , h_box = max (projected_xs ) - xt_box , max (projected_ys ) - yt_box
148
148
149
+ if not with_descent :
150
+ yt_box += d
151
+ h_box -= d
152
+
149
153
tr = mtransforms .Affine2D ().rotate (theta )
150
154
151
155
x_box , y_box = tr .transform_point ((xt_box , yt_box ))
@@ -211,7 +215,6 @@ def __init__(self,
211
215
self ._linespacing = linespacing
212
216
self .set_rotation_mode (rotation_mode )
213
217
self .update (kwargs )
214
- #self.set_bbox(dict(pad=0))
215
218
216
219
def __getstate__ (self ):
217
220
d = super (Text , self ).__getstate__ ()
@@ -458,10 +461,13 @@ def set_bbox(self, rectprops):
458
461
459
462
if rectprops is not None :
460
463
props = rectprops .copy ()
461
- # Dump the pad kwarg; we still need to figure out how to
462
- # use it to expand the box, for backwards compatibility.
463
- pad = props .pop ('pad' , 4 ) # noqa
464
+ pad = props .pop ('pad' , 4 ) # in points; hardwired default
464
465
boxstyle = props .pop ("boxstyle" , "square" )
466
+ # If pad is in the boxstyle string, it will be passed
467
+ # directly to the FancyBboxPatch as font units.
468
+ if 'pad' not in boxstyle :
469
+ boxstyle += ",pad=%0.2f" % (pad / self .get_size ())
470
+
465
471
bbox_transmuter = props .pop ("bbox_transmuter" , None )
466
472
467
473
self ._bbox_patch = FancyBboxPatch (
@@ -501,7 +507,8 @@ def update_bbox_position_size(self, renderer):
501
507
502
508
posx , posy = trans .transform_point ((posx , posy ))
503
509
504
- x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
510
+ x_box , y_box , w_box , h_box = _get_textbox (self , renderer ,
511
+ with_descent = False )
505
512
self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
506
513
theta = np .deg2rad (self .get_rotation ())
507
514
tr = mtransforms .Affine2D ().rotate (theta )
@@ -517,7 +524,8 @@ def _draw_bbox(self, renderer, posx, posy):
517
524
(FancyBboxPatch), and draw
518
525
"""
519
526
520
- x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
527
+ x_box , y_box , w_box , h_box = _get_textbox (self , renderer ,
528
+ with_descent = False )
521
529
self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
522
530
theta = np .deg2rad (self .get_rotation ())
523
531
tr = mtransforms .Affine2D ().rotate (theta )
0 commit comments