@@ -93,7 +93,8 @@ def get_rotation(rotation):
93
93
animated [True | False]
94
94
backgroundcolor any matplotlib color
95
95
bbox rectangle prop dict plus key 'pad' which is a
96
- pad in points
96
+ pad in points; if a boxstyle is supplied, then
97
+ pad is instead a fraction of the font size
97
98
clip_box a matplotlib.transform.Bbox instance
98
99
clip_on [True | False]
99
100
color any matplotlib color
@@ -137,7 +138,7 @@ def get_rotation(rotation):
137
138
# function as a method with some refactoring of _get_layout method.
138
139
139
140
140
- def _get_textbox (text , renderer , with_descent = True ):
141
+ def _get_textbox (text , renderer ):
141
142
"""
142
143
Calculate the bounding box of the text. Unlike
143
144
:meth:`matplotlib.text.Text.get_extents` method, The bbox size of
@@ -165,10 +166,6 @@ def _get_textbox(text, renderer, with_descent=True):
165
166
xt_box , yt_box = min (projected_xs ), min (projected_ys )
166
167
w_box , h_box = max (projected_xs ) - xt_box , max (projected_ys ) - yt_box
167
168
168
- if not with_descent :
169
- yt_box += d
170
- h_box -= d
171
-
172
169
tr = mtransforms .Affine2D ().rotate (theta )
173
170
174
171
x_box , y_box = tr .transform_point ((xt_box , yt_box ))
@@ -228,7 +225,6 @@ def __init__(self,
228
225
self ._multialignment = multialignment
229
226
self ._rotation = rotation
230
227
self ._fontproperties = fontproperties
231
- self ._bbox = None
232
228
self ._bbox_patch = None # a FancyBboxPatch instance
233
229
self ._renderer = None
234
230
if linespacing is None :
@@ -237,6 +233,14 @@ def __init__(self,
237
233
self .set_rotation_mode (rotation_mode )
238
234
self .update (kwargs )
239
235
236
+ def update (self , kwargs ):
237
+ """
238
+ Update properties from a dictionary.
239
+ """
240
+ bbox = kwargs .pop ('bbox' , None )
241
+ super (Text , self ).update (kwargs )
242
+ self .set_bbox (bbox ) # depends on font properties
243
+
240
244
def __getstate__ (self ):
241
245
d = super (Text , self ).__getstate__ ()
242
246
# remove the cached _renderer (if it exists)
@@ -484,12 +488,18 @@ def set_bbox(self, rectprops):
484
488
485
489
if rectprops is not None :
486
490
props = rectprops .copy ()
487
- pad = props .pop ('pad' , 4 ) # in points; hardwired default
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 ())
491
+ boxstyle = props .pop ("boxstyle" , None )
492
+ pad = props .pop ("pad" , None )
493
+ if boxstyle is None :
494
+ boxstyle = "square"
495
+ if pad is None :
496
+ pad = 4 # points
497
+ pad /= self .get_size () # to fraction of font size
498
+ else :
499
+ if pad is None :
500
+ pad = 0.3
501
+ if "pad" not in boxstyle :
502
+ boxstyle += ",pad=%0.2f" % pad
493
503
494
504
bbox_transmuter = props .pop ("bbox_transmuter" , None )
495
505
@@ -530,8 +540,7 @@ def update_bbox_position_size(self, renderer):
530
540
531
541
posx , posy = trans .transform_point ((posx , posy ))
532
542
533
- x_box , y_box , w_box , h_box = _get_textbox (self , renderer ,
534
- with_descent = True )
543
+ x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
535
544
self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
536
545
theta = np .deg2rad (self .get_rotation ())
537
546
tr = mtransforms .Affine2D ().rotate (theta )
@@ -547,8 +556,7 @@ def _draw_bbox(self, renderer, posx, posy):
547
556
(FancyBboxPatch), and draw
548
557
"""
549
558
550
- x_box , y_box , w_box , h_box = _get_textbox (self , renderer ,
551
- with_descent = True )
559
+ x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
552
560
self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
553
561
theta = np .deg2rad (self .get_rotation ())
554
562
tr = mtransforms .Affine2D ().rotate (theta )
@@ -2143,9 +2151,11 @@ def _update_position_xytext(self, renderer, xy_pixel):
2143
2151
" use 'headlength' to set the head length in points." )
2144
2152
headlength = d .pop ('headlength' , 12 )
2145
2153
2146
- stylekw = dict (head_length = headlength / ms ,
2147
- head_width = headwidth / ms ,
2148
- tail_width = width / ms )
2154
+ to_style = self .figure .dpi / (72 * ms )
2155
+
2156
+ stylekw = dict (head_length = headlength * to_style ,
2157
+ head_width = headwidth * to_style ,
2158
+ tail_width = width * to_style )
2149
2159
2150
2160
self .arrow_patch .set_arrowstyle ('simple' , ** stylekw )
2151
2161
0 commit comments