Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b59d8a3

Browse files
committed
Resolve 'text ignores rotational part of transformation' bug (#698)
Considering the text rotation don't get transformed may by a desired behavior (such as text for annotation to some data point). Here made it as an option to control whether or not the text rotation get transformed.
1 parent 09d8da2 commit b59d8a3

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

lib/matplotlib/text.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def __init__(self,
136136
rotation_mode=None,
137137
usetex=None, # defaults to rcParams['text.usetex']
138138
wrap=False,
139+
rotation_transformed=False,
139140
**kwargs
140141
):
141142
"""
@@ -157,6 +158,7 @@ def __init__(self,
157158
self.set_horizontalalignment(horizontalalignment)
158159
self._multialignment = multialignment
159160
self._rotation = rotation
161+
self._rotation_transformed = rotation_transformed
160162
self._bbox_patch = None # a FancyBboxPatch instance
161163
self._renderer = None
162164
if linespacing is None:
@@ -228,7 +230,16 @@ def _get_multialignment(self):
228230

229231
def get_rotation(self):
230232
"""Return the text angle in degrees between 0 and 360."""
231-
return get_rotation(self._rotation) # string_or_number -> number
233+
if self.get_rotation_transformed():
234+
angle = get_rotation(self._rotation)
235+
x, y = self.get_unitless_position()
236+
return self.get_transform().transform_angles([angle, ], [[x, y]])
237+
else:
238+
return get_rotation(self._rotation) # string_or_number -> number
239+
240+
def get_rotation_transformed(self):
241+
"""Return if the text rotation get transformed or not."""
242+
return self._rotation_transformed
232243

233244
def set_rotation_mode(self, m):
234245
"""
@@ -259,6 +270,7 @@ def update_from(self, other):
259270
self._fontproperties = other._fontproperties.copy()
260271
self._usetex = other._usetex
261272
self._rotation = other._rotation
273+
self._rotation_transformed = other._rotation_transformed
262274
self._picker = other._picker
263275
self._linespacing = other._linespacing
264276
self.stale = True
@@ -843,6 +855,7 @@ def get_prop_tup(self, renderer=None):
843855
self._verticalalignment, self._horizontalalignment,
844856
hash(self._fontproperties),
845857
self._rotation, self._rotation_mode,
858+
self._rotation_transformed,
846859
self.figure.dpi, weakref.ref(renderer),
847860
self._linespacing
848861
)
@@ -1132,6 +1145,17 @@ def set_rotation(self, s):
11321145
self._rotation = s
11331146
self.stale = True
11341147

1148+
def set_rotation_transformed(self, t):
1149+
"""
1150+
Set if the text rotation get transformed or not.
1151+
1152+
Parameters
1153+
----------
1154+
t : bool
1155+
"""
1156+
self._rotation_transformed = t
1157+
self.stale = True
1158+
11351159
def set_verticalalignment(self, align):
11361160
"""
11371161
Set the vertical alignment.

0 commit comments

Comments
 (0)