9
9
10
10
import numpy as np
11
11
12
- from . import _api , artist , cbook , docstring , rcParams
12
+ import matplotlib as mpl
13
+ from . import _api , artist , cbook , docstring
13
14
from .artist import Artist
14
15
from .font_manager import FontProperties
15
16
from .patches import FancyArrowPatch , FancyBboxPatch , Rectangle
@@ -65,12 +66,13 @@ def get_rotation(rotation):
65
66
66
67
def _get_textbox (text , renderer ):
67
68
"""
68
- Calculate the bounding box of the text. Unlike
69
- :meth:`matplotlib.text.Text.get_extents` method, The bbox size of
70
- the text before the rotation is calculated.
69
+ Calculate the bounding box of the text.
70
+
71
+ The bbox position takes text rotation into account, but the width and
72
+ height are those of the unrotated box (unlike `.Text.get_window_extent`).
71
73
"""
72
74
# TODO : This function may move into the Text class as a method. As a
73
- # matter of fact, The information from the _get_textbox function
75
+ # matter of fact, the information from the _get_textbox function
74
76
# should be available during the Text._get_layout() call, which is
75
77
# called within the _get_textbox. So, it would better to move this
76
78
# function as a method with some refactoring of _get_layout method.
@@ -150,7 +152,8 @@ def __init__(self,
150
152
self ._x , self ._y = x , y
151
153
self ._text = ''
152
154
self .set_text (text )
153
- self .set_color (color if color is not None else rcParams ["text.color" ])
155
+ self .set_color (
156
+ color if color is not None else mpl .rcParams ["text.color" ])
154
157
self .set_fontproperties (fontproperties )
155
158
self .set_usetex (usetex )
156
159
self .set_wrap (wrap )
@@ -490,17 +493,12 @@ def update_bbox_position_size(self, renderer):
490
493
This method should be used when the position and size of the bbox needs
491
494
to be updated before actually drawing the bbox.
492
495
"""
493
-
494
496
if self ._bbox_patch :
495
-
496
- trans = self .get_transform ()
497
-
498
497
# don't use self.get_unitless_position here, which refers to text
499
498
# position in Text:
500
499
posx = float (self .convert_xunits (self ._x ))
501
500
posy = float (self .convert_yunits (self ._y ))
502
-
503
- posx , posy = trans .transform ((posx , posy ))
501
+ posx , posy = self .get_transform ().transform ((posx , posy ))
504
502
505
503
x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
506
504
self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
@@ -511,22 +509,6 @@ def update_bbox_position_size(self, renderer):
511
509
fontsize_in_pixel = renderer .points_to_pixels (self .get_size ())
512
510
self ._bbox_patch .set_mutation_scale (fontsize_in_pixel )
513
511
514
- def _draw_bbox (self , renderer , posx , posy ):
515
- """
516
- Update the location and size of the bbox (`.patches.FancyBboxPatch`),
517
- and draw.
518
- """
519
-
520
- x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
521
- self ._bbox_patch .set_bounds (0. , 0. , w_box , h_box )
522
- theta = np .deg2rad (self .get_rotation ())
523
- tr = Affine2D ().rotate (theta )
524
- tr = tr .translate (posx + x_box , posy + y_box )
525
- self ._bbox_patch .set_transform (tr )
526
- fontsize_in_pixel = renderer .points_to_pixels (self .get_size ())
527
- self ._bbox_patch .set_mutation_scale (fontsize_in_pixel )
528
- self ._bbox_patch .draw (renderer )
529
-
530
512
def _update_clip_properties (self ):
531
513
clipprops = dict (clip_box = self .clipbox ,
532
514
clip_path = self ._clippath ,
@@ -697,9 +679,11 @@ def draw(self, renderer):
697
679
return
698
680
canvasw , canvash = renderer .get_canvas_width_height ()
699
681
700
- # draw the FancyBboxPatch
682
+ # Update the location and size of the bbox
683
+ # (`.patches.FancyBboxPatch`), and draw it.
701
684
if textobj ._bbox_patch :
702
- textobj ._draw_bbox (renderer , posx , posy )
685
+ self .update_bbox_position_size (renderer )
686
+ self ._bbox_patch .draw (renderer )
703
687
704
688
gc = renderer .new_gc ()
705
689
gc .set_foreground (textobj .get_color ())
@@ -721,7 +705,7 @@ def draw(self, renderer):
721
705
if textobj .get_path_effects ():
722
706
from matplotlib .patheffects import PathEffectRenderer
723
707
textrenderer = PathEffectRenderer (
724
- textobj .get_path_effects (), renderer )
708
+ textobj .get_path_effects (), renderer )
725
709
else :
726
710
textrenderer = renderer
727
711
@@ -1262,7 +1246,7 @@ def set_usetex(self, usetex):
1262
1246
:rc:`text.usetex`.
1263
1247
"""
1264
1248
if usetex is None :
1265
- self ._usetex = rcParams ['text.usetex' ]
1249
+ self ._usetex = mpl . rcParams ['text.usetex' ]
1266
1250
else :
1267
1251
self ._usetex = bool (usetex )
1268
1252
self .stale = True
@@ -1461,7 +1445,6 @@ def _get_xy_transform(self, renderer, s):
1461
1445
if xy0 is not None :
1462
1446
# reference x, y in display coordinate
1463
1447
ref_x , ref_y = xy0
1464
- from matplotlib .transforms import Affine2D
1465
1448
if unit == "points" :
1466
1449
# dots per points
1467
1450
dpp = self .figure .get_dpi () / 72.
@@ -1942,7 +1925,6 @@ def draw(self, renderer):
1942
1925
if not self .get_visible () or not self ._check_xy (renderer ):
1943
1926
return
1944
1927
self .update_positions (renderer )
1945
- self .update_bbox_position_size (renderer )
1946
1928
if self .arrow_patch is not None : # FancyArrowPatch
1947
1929
if self .arrow_patch .figure is None and self .figure is not None :
1948
1930
self .arrow_patch .figure = self .figure
0 commit comments