@@ -1081,6 +1081,61 @@ def test__dim_list_handler_mixed():
10811081 assert set (combos ) == {("A" ,), ("B" ,)}
10821082
10831083
1084+ class TestAlignYAxes :
1085+ """Test the _align_y_axes method with various axis configurations."""
1086+
1087+ @pytest .fixture
1088+ def mock_axes (self ):
1089+ """Create mock axes for testing."""
1090+ _ , ax = plt .subplots ()
1091+ ax2 = ax .twinx ()
1092+ return ax , ax2
1093+
1094+ @pytest .mark .parametrize (
1095+ "ax1_limits,ax2_limits,expected_ax1_limits,expected_ax2_limits,description" ,
1096+ [
1097+ ((0 , 10 ), (0 , 20 ), (0 , 10 ), (0 , 20 ), "both_positive" ),
1098+ ((- 10 , 0 ), (- 20 , 0 ), (- 10 , 0 ), (- 20 , 0 ), "both_negative" ),
1099+ ((- 5 , 10 ), (0 , 20 ), (- 5 , 10 ), (- 10 , 20 ), "ax1_mixed_ax2_positive" ),
1100+ ((- 10 , 0 ), (- 5 , 20 ), (- 10 , 40 ), (- 5 , 20 ), "ax1_negative_ax2_mixed" ),
1101+ ((- 2 , 10 ), (- 5 , 20 ), (- 2.5 , 10 ), (- 5 , 20 ), "both_mixed_ax1_ratio_smaller" ),
1102+ ((- 5 , 10 ), (- 2 , 20 ), (- 5 , 10 ), (- 10 , 20 ), "both_mixed_ax2_ratio_smaller" ),
1103+ ((- 10 , 0 ), (0 , 20 ), (- 10 , 10 ), (- 20 , 20 ), "ax1_fully_negative" ),
1104+ ((- 2 , 0 ), (0 , 10 ), (- 2 , 2 ), (- 10 , 10 ), "ax2_fully_negative" ),
1105+ ],
1106+ )
1107+ def test_align_y_axes_various_scenarios (
1108+ self ,
1109+ mock_axes ,
1110+ ax1_limits ,
1111+ ax2_limits ,
1112+ expected_ax1_limits ,
1113+ expected_ax2_limits ,
1114+ description ,
1115+ ):
1116+ """Test _align_y_axes with various axis limit scenarios."""
1117+ ax , ax2 = mock_axes
1118+ suite = MMMPlotSuite (az .InferenceData ())
1119+
1120+ # Set initial limits
1121+ ax .set_ylim (ax1_limits )
1122+ ax2 .set_ylim (ax2_limits )
1123+
1124+ # Call the method
1125+ suite ._align_y_axes (ax , ax2 )
1126+
1127+ # Check results
1128+ actual_ax1_limits = ax .get_ylim ()
1129+ actual_ax2_limits = ax2 .get_ylim ()
1130+
1131+ assert actual_ax1_limits == pytest .approx (expected_ax1_limits , rel = 1e-10 ), (
1132+ f"Axis 1 limits incorret in: { description } "
1133+ )
1134+ assert actual_ax2_limits == pytest .approx (expected_ax2_limits , rel = 1e-10 ), (
1135+ f"Axis 2 limits incorret in: { description } "
1136+ )
1137+
1138+
10841139class TestPlotBudgetAllocationBars :
10851140 """Test the _plot_budget_allocation_bars method and its integration with _align_y_axes."""
10861141
0 commit comments