@@ -529,3 +529,39 @@ def test_loc_positions():
529
529
for loc in TEXT_LOCS :
530
530
ax .format (abc = "a." , abcloc = loc )
531
531
uplt .close (fig )
532
+
533
+
534
+ @pytest .mark .parametrize ("angle" , [0 , 45 , 89 , 63 , 90 ])
535
+ def test_axis_label_anchor (angle ):
536
+ """
537
+ Check if the rotation of the xticklabels is correctly handle by xrotation and yrotation
538
+ """
539
+ fig , ax = uplt .subplots (ncols = 2 )
540
+ ax [0 ].format (xrotation = angle , yrotation = angle )
541
+
542
+ # Need fixed ticks for it to work (set locator explicitly)
543
+ ax [1 ].set_xticks (ax [1 ].get_xticks ())
544
+ ax [1 ].set_yticks (ax [1 ].get_yticks ())
545
+
546
+ kw = dict ()
547
+ if angle in (0 , 90 , - 90 ):
548
+ kw ["ha" ] = "right"
549
+ ax [1 ].set_xticklabels (
550
+ ax [1 ].get_xticklabels (), rotation = angle , rotation_mode = "anchor" , ** kw
551
+ )
552
+ ax [1 ].set_yticklabels (
553
+ ax [1 ].get_yticklabels (), rotation = angle , rotation_mode = "anchor" , ** kw
554
+ )
555
+
556
+ # Ticks should be in the same position
557
+ for tick1 , tick2 in zip (ax [0 ].get_xticklabels (), ax [1 ].get_xticklabels ()):
558
+ assert tick1 .get_rotation () == angle
559
+ assert tick2 .get_rotation () == angle
560
+ assert tick1 .get_position ()[0 ] == tick2 .get_position ()[0 ]
561
+ assert tick1 .get_position ()[1 ] == tick2 .get_position ()[1 ]
562
+
563
+ for tick1 , tick2 in zip (ax [0 ].get_yticklabels (), ax [1 ].get_yticklabels ()):
564
+ assert tick1 .get_rotation () == angle
565
+ assert tick2 .get_rotation () == angle
566
+ assert tick1 .get_position ()[0 ] == tick2 .get_position ()[0 ]
567
+ assert tick1 .get_position ()[1 ] == tick2 .get_position ()[1 ]
0 commit comments