@@ -129,6 +129,7 @@ def get_rotation(rotation):
129
129
x float
130
130
y float
131
131
zorder any number
132
+ trans_rotate [True | False]
132
133
========================== ===============================================
133
134
""" )
134
135
@@ -197,6 +198,7 @@ def __init__(self,
197
198
rotation_mode = None ,
198
199
usetex = None , # defaults to rcParams['text.usetex']
199
200
wrap = False ,
201
+ trans_rotate = None ,
200
202
** kwargs
201
203
):
202
204
"""
@@ -232,6 +234,7 @@ def __init__(self,
232
234
linespacing = 1.2 # Maybe use rcParam later.
233
235
self ._linespacing = linespacing
234
236
self .set_rotation_mode (rotation_mode )
237
+ self .set_trans_rotate (trans_rotate )
235
238
self .update (kwargs )
236
239
237
240
def update (self , kwargs ):
@@ -308,6 +311,19 @@ def set_rotation_mode(self, m):
308
311
raise ValueError ("Unknown rotation_mode : %s" % repr (m ))
309
312
self .stale = True
310
313
314
+ def set_trans_rotate (self , tr ):
315
+ """
316
+ Set the boolean flag that determines
317
+ if the text should be rotated via
318
+ transformation or not
319
+ """
320
+ self ._trans_rotate = bool (tr )
321
+ self .stale = True
322
+
323
+ def get_trans_rotate (self ):
324
+ "get transform rotation boolean"
325
+ return self ._trans_rotate
326
+
311
327
def get_rotation_mode (self ):
312
328
"get text rotation mode"
313
329
return self ._rotation_mode
@@ -753,9 +769,16 @@ def draw(self, renderer):
753
769
# position in Text, and dash position in TextWithDash:
754
770
posx = float (textobj .convert_xunits (textobj ._x ))
755
771
posy = float (textobj .convert_yunits (textobj ._y ))
772
+ posxangle = posx + 1
773
+ posyangle = posy
756
774
if not np .isfinite (posx ) or not np .isfinite (posy ):
757
775
raise ValueError ("posx and posy should be finite values" )
758
776
posx , posy = trans .transform_point ((posx , posy ))
777
+ transangle = 0
778
+ if self .get_trans_rotate ():
779
+ posxangle , posyangle = trans .transform_point (
780
+ (posxangle , posyangle ))
781
+ transangle = math .atan2 (posyangle - posy , posxangle - posx )
759
782
canvasw , canvash = renderer .get_canvas_width_height ()
760
783
761
784
# draw the FancyBboxPatch
@@ -768,7 +791,7 @@ def draw(self, renderer):
768
791
gc .set_url (textobj ._url )
769
792
textobj ._set_gc_clip (gc )
770
793
771
- angle = textobj .get_rotation ()
794
+ angle = ( textobj .get_rotation ()+ np . rad2deg ( transangle )) % 360
772
795
773
796
for line , wh , x , y in info :
774
797
0 commit comments