@@ -477,6 +477,42 @@ def test_twin_inherit_autoscale_setting():
477477 assert not ax_y_off .get_autoscaley_on ()
478478
479479
480+ @pytest .mark .parametrize ("twin" , ("x" , "y" ))
481+ def test_twin_respects_position_after_set_position (twin ):
482+ fig , ax = plt .subplots ()
483+
484+ ax .set_position ([0.2 , 0.2 , 0.5 , 0.5 ])
485+ ax2 = getattr (ax , f"twin{ twin } " )()
486+
487+ assert_allclose (ax .get_position (original = True ).bounds ,
488+ ax2 .get_position (original = True ).bounds )
489+
490+ assert_allclose (ax .get_position (original = False ).bounds ,
491+ ax2 .get_position (original = False ).bounds )
492+
493+
494+ @pytest .mark .parametrize ("twin" , ("x" , "y" ))
495+ def test_twin_keeps_layout_participation_for_layout_managed_axes (twin ):
496+ fig , ax = plt .subplots ()
497+
498+ ax2 = getattr (ax , f"twin{ twin } " )()
499+
500+ assert ax .get_in_layout ()
501+ assert ax2 .get_in_layout ()
502+
503+
504+ @pytest .mark .parametrize ("twin" , ("x" , "y" ))
505+ def test_twin_stays_aligned_after_constrained_layout (twin ):
506+ fig , ax = plt .subplots (constrained_layout = True )
507+
508+ ax .set_position ([0.2 , 0.2 , 0.5 , 0.5 ])
509+ ax2 = getattr (ax , f"twin{ twin } " )()
510+
511+ fig .canvas .draw ()
512+
513+ assert_allclose (ax .get_position ().bounds , ax2 .get_position ().bounds )
514+
515+
480516def test_inverted_cla ():
481517 # GitHub PR #5450. Setting autoscale should reset
482518 # axes to be non-inverted.
0 commit comments