Skip to content

Commit 3dd913e

Browse files
committed
improve arg name, docstring, add test
1 parent ba7a00a commit 3dd913e

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
import warnings
33

44
import numpy as np
5-
from numpy.testing import assert_almost_equal
65
import pytest
6+
from numpy.testing import assert_almost_equal
77

88
import matplotlib
9-
from matplotlib.backend_bases import MouseEvent
109
import matplotlib.patches as mpatches
1110
import matplotlib.pyplot as plt
11+
import matplotlib.transforms as mtransforms
12+
from matplotlib.backend_bases import MouseEvent
1213
from matplotlib.testing.decorators import check_figures_equal, image_comparison
1314

14-
1515
needs_usetex = pytest.mark.skipif(
1616
not matplotlib.checkdep_usetex(True),
1717
reason="This test needs a TeX installation")
@@ -635,3 +635,12 @@ def test_buffer_size(fig_test, fig_ref):
635635
ax = fig_ref.add_subplot()
636636
ax.set_yticks([0, 1])
637637
ax.set_yticklabels(["€", ""])
638+
639+
640+
def test_transform_rotates_text():
641+
ax = plt.gca()
642+
transform = mtransforms.Affine2D().rotate_deg(30)
643+
text = ax.text(0, 0, 'test', transform=transform,
644+
transform_rotates_text=True)
645+
result = text.get_rotation()[0]
646+
assert_almost_equal(result, 30)

lib/matplotlib/text.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(self,
130130
rotation_mode=None,
131131
usetex=None, # defaults to rcParams['text.usetex']
132132
wrap=False,
133-
rotation_transformed=False,
133+
transform_rotates_text=False,
134134
**kwargs
135135
):
136136
"""
@@ -159,7 +159,7 @@ def __init__(self,
159159
self.set_horizontalalignment(horizontalalignment)
160160
self._multialignment = multialignment
161161
self._rotation = rotation
162-
self._rotation_transformed = rotation_transformed
162+
self._transform_rotates_text = transform_rotates_text
163163
self._fontproperties = fontproperties
164164
self._bbox_patch = None # a FancyBboxPatch instance
165165
self._renderer = None
@@ -237,16 +237,18 @@ def _get_multialignment(self):
237237

238238
def get_rotation(self):
239239
"""Return the text angle as float in degrees."""
240-
if self.get_rotation_transformed():
240+
if self.get_transform_rotates_text():
241241
angle = get_rotation(self._rotation)
242242
x, y = self.get_unitless_position()
243243
return self.get_transform().transform_angles([angle, ], [[x, y]])
244244
else:
245245
return get_rotation(self._rotation) # string_or_number -> number
246246

247-
def get_rotation_transformed(self):
248-
"""Return if the text rotation get transformed or not."""
249-
return self._rotation_transformed
247+
def get_transform_rotates_text(self):
248+
"""
249+
Return whether rotations of the transform affect the text direction.
250+
"""
251+
return self._transform_rotates_text
250252

251253
def set_rotation_mode(self, m):
252254
"""
@@ -276,7 +278,7 @@ def update_from(self, other):
276278
self._horizontalalignment = other._horizontalalignment
277279
self._fontproperties = other._fontproperties.copy()
278280
self._rotation = other._rotation
279-
self._rotation_transformed = other._rotation_transformed
281+
self._transform_rotates_text = other._transform_rotates_text
280282
self._picker = other._picker
281283
self._linespacing = other._linespacing
282284
self.stale = True
@@ -861,7 +863,7 @@ def get_prop_tup(self, renderer=None):
861863
self._verticalalignment, self._horizontalalignment,
862864
hash(self._fontproperties),
863865
self._rotation, self._rotation_mode,
864-
self._rotation_transformed,
866+
self._transform_rotates_text,
865867
self.figure.dpi, weakref.ref(renderer),
866868
self._linespacing
867869
)
@@ -1147,15 +1149,15 @@ def set_rotation(self, s):
11471149
self._rotation = s
11481150
self.stale = True
11491151

1150-
def set_rotation_transformed(self, t):
1152+
def set_transform_rotates_text(self, t):
11511153
"""
1152-
Set if the text rotation get transformed or not.
1154+
Whether rotations of the transform affect the text direction.
11531155
11541156
Parameters
11551157
----------
11561158
t : bool
11571159
"""
1158-
self._rotation_transformed = t
1160+
self._transform_rotates_text = t
11591161
self.stale = True
11601162

11611163
def set_verticalalignment(self, align):

0 commit comments

Comments
 (0)