@@ -310,7 +310,7 @@ def set_rotation_mode(self, m):
310
310
if m is None :
311
311
m = "default"
312
312
else :
313
- _api .check_in_list (("anchor" , "default" ), rotation_mode = m )
313
+ _api .check_in_list (("anchor" , "default" , "xtick" ), rotation_mode = m )
314
314
self ._rotation_mode = m
315
315
self .stale = True
316
316
@@ -454,6 +454,9 @@ def _get_layout(self, renderer):
454
454
455
455
rotation_mode = self .get_rotation_mode ()
456
456
if rotation_mode != "anchor" :
457
+ if rotation_mode == 'xtick' :
458
+ angle = self .get_rotation ()
459
+ halign = self .ha_for_angle (angle )
457
460
# compute the text location in display coords and the offsets
458
461
# necessary to align the bbox with that location
459
462
if halign == 'center' :
@@ -1380,6 +1383,18 @@ def set_fontname(self, fontname):
1380
1383
"""
1381
1384
self .set_fontfamily (fontname )
1382
1385
1386
+ def ha_for_angle (self , angle ):
1387
+ """
1388
+ Determines horizontal alignment ('ha') based on the angle of rotation.
1389
+ """
1390
+ if (angle < 5 or 85 <= angle < 105 or 355 <= angle <= 360 or
1391
+ 170 <= angle < 190 or 265 <= angle < 275 ):
1392
+ return 'center'
1393
+ elif 5 <= angle < 85 or 190 <= angle < 265 :
1394
+ return 'right'
1395
+ elif 105 <= angle < 170 or 275 <= angle < 355 :
1396
+ return 'left'
1397
+
1383
1398
1384
1399
class OffsetFrom :
1385
1400
"""Callable helper class for working with `Annotation`."""
@@ -2031,5 +2046,4 @@ def get_tightbbox(self, renderer=None):
2031
2046
return Bbox .null ()
2032
2047
return super ().get_tightbbox (renderer )
2033
2048
2034
-
2035
2049
_docstring .interpd .register (Annotation = Annotation .__init__ .__doc__ )
0 commit comments