@@ -93,7 +93,8 @@ def get_rotation(rotation):
9393 animated [True | False]
9494 backgroundcolor any matplotlib color
9595 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
9798 clip_box a matplotlib.transform.Bbox instance
9899 clip_on [True | False]
99100 color any matplotlib color
@@ -137,7 +138,7 @@ def get_rotation(rotation):
137138# function as a method with some refactoring of _get_layout method.
138139
139140
140- def _get_textbox (text , renderer , with_descent = True ):
141+ def _get_textbox (text , renderer ):
141142 """
142143 Calculate the bounding box of the text. Unlike
143144 :meth:`matplotlib.text.Text.get_extents` method, The bbox size of
@@ -165,10 +166,6 @@ def _get_textbox(text, renderer, with_descent=True):
165166 xt_box , yt_box = min (projected_xs ), min (projected_ys )
166167 w_box , h_box = max (projected_xs ) - xt_box , max (projected_ys ) - yt_box
167168
168- if not with_descent :
169- yt_box += d
170- h_box -= d
171-
172169 tr = mtransforms .Affine2D ().rotate (theta )
173170
174171 x_box , y_box = tr .transform_point ((xt_box , yt_box ))
@@ -228,7 +225,6 @@ def __init__(self,
228225 self ._multialignment = multialignment
229226 self ._rotation = rotation
230227 self ._fontproperties = fontproperties
231- self ._bbox = None
232228 self ._bbox_patch = None # a FancyBboxPatch instance
233229 self ._renderer = None
234230 if linespacing is None :
@@ -237,6 +233,14 @@ def __init__(self,
237233 self .set_rotation_mode (rotation_mode )
238234 self .update (kwargs )
239235
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+
240244 def __getstate__ (self ):
241245 d = super (Text , self ).__getstate__ ()
242246 # remove the cached _renderer (if it exists)
@@ -484,12 +488,18 @@ def set_bbox(self, rectprops):
484488
485489 if rectprops is not None :
486490 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
493503
494504 bbox_transmuter = props .pop ("bbox_transmuter" , None )
495505
@@ -530,8 +540,7 @@ def update_bbox_position_size(self, renderer):
530540
531541 posx , posy = trans .transform_point ((posx , posy ))
532542
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 )
535544 self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
536545 theta = np .deg2rad (self .get_rotation ())
537546 tr = mtransforms .Affine2D ().rotate (theta )
@@ -547,8 +556,7 @@ def _draw_bbox(self, renderer, posx, posy):
547556 (FancyBboxPatch), and draw
548557 """
549558
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 )
552560 self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
553561 theta = np .deg2rad (self .get_rotation ())
554562 tr = mtransforms .Affine2D ().rotate (theta )
@@ -2143,9 +2151,11 @@ def _update_position_xytext(self, renderer, xy_pixel):
21432151 " use 'headlength' to set the head length in points." )
21442152 headlength = d .pop ('headlength' , 12 )
21452153
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 )
21492159
21502160 self .arrow_patch .set_arrowstyle ('simple' , ** stylekw )
21512161
0 commit comments