MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / _get_textbox

Function _get_textbox

site-packages/matplotlib/text.py:71–106  ·  view source on GitHub ↗

Calculate the bounding box of the text. Unlike :meth:`matplotlib.text.Text.get_extents` method, The bbox size of the text before the rotation is calculated.

(text, renderer)

Source from the content-addressed store, hash-verified

69
70
71def _get_textbox(text, renderer):
72 """
73 Calculate the bounding box of the text. Unlike
74 :meth:`matplotlib.text.Text.get_extents` method, The bbox size of
75 the text before the rotation is calculated.
76 """
77 # TODO : This function may move into the Text class as a method. As a
78 # matter of fact, The information from the _get_textbox function
79 # should be available during the Text._get_layout() call, which is
80 # called within the _get_textbox. So, it would better to move this
81 # function as a method with some refactoring of _get_layout method.
82
83 projected_xs = []
84 projected_ys = []
85
86 theta = np.deg2rad(text.get_rotation())
87 tr = Affine2D().rotate(-theta)
88
89 _, parts, d = text._get_layout(renderer)
90
91 for t, wh, x, y in parts:
92 w, h = wh
93
94 xt1, yt1 = tr.transform_point((x, y))
95 yt1 -= d
96 xt2, yt2 = xt1 + w, yt1 + h
97
98 projected_xs.extend([xt1, xt2])
99 projected_ys.extend([yt1, yt2])
100
101 xt_box, yt_box = min(projected_xs), min(projected_ys)
102 w_box, h_box = max(projected_xs) - xt_box, max(projected_ys) - yt_box
103
104 x_box, y_box = Affine2D().rotate(theta).transform_point((xt_box, yt_box))
105
106 return x_box, y_box, w_box, h_box
107
108
109@cbook._define_aliases({

Callers 2

_draw_bboxMethod · 0.85

Calls 8

Affine2DClass · 0.90
minFunction · 0.85
maxFunction · 0.85
rotateMethod · 0.80
_get_layoutMethod · 0.80
get_rotationMethod · 0.45
transform_pointMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected