@@ -7118,6 +7118,42 @@ def test_spines_properbbox_after_zoom():
71187118 np .testing .assert_allclose (bb .get_points (), bb2 .get_points (), rtol = 1e-6 )
71197119
71207120
7121+ def test_limits_after_scroll_zoom ():
7122+ fig , ax = plt .subplots ()
7123+ #
7124+ xlim = (- 0.5 , 0.5 )
7125+ ylim = (- 1 , 2 )
7126+ ax .set_xlim (xlim )
7127+ ax .set_ylim (ymin = ylim [0 ], ymax = ylim [1 ])
7128+ # This is what scroll zoom calls:
7129+ # Zoom with factor 1, small numerical change
7130+ ax ._set_view_from_bbox ((200 , 200 , 1. ))
7131+ np .testing .assert_allclose (xlim , ax .get_xlim (), atol = 1e-16 )
7132+ np .testing .assert_allclose (ylim , ax .get_ylim (), atol = 1e-16 )
7133+
7134+ # Zoom in
7135+ ax ._set_view_from_bbox ((200 , 200 , 2. ))
7136+ # Hard-coded values
7137+ new_xlim = (- 0.3790322580645161 , 0.12096774193548387 )
7138+ new_ylim = (- 0.40625 , 1.09375 )
7139+
7140+ res_xlim = ax .get_xlim ()
7141+ res_ylim = ax .get_ylim ()
7142+ np .testing .assert_allclose (res_xlim [1 ] - res_xlim [0 ], 0.5 )
7143+ np .testing .assert_allclose (res_ylim [1 ] - res_ylim [0 ], 1.5 )
7144+ np .testing .assert_allclose (new_xlim , res_xlim , atol = 1e-16 )
7145+ np .testing .assert_allclose (new_ylim , res_ylim )
7146+
7147+ # Zoom out, should be same as before, except for numerical issues
7148+ ax ._set_view_from_bbox ((200 , 200 , 0.5 ))
7149+ res_xlim = ax .get_xlim ()
7150+ res_ylim = ax .get_ylim ()
7151+ np .testing .assert_allclose (res_xlim [1 ] - res_xlim [0 ], 1 )
7152+ np .testing .assert_allclose (res_ylim [1 ] - res_ylim [0 ], 3 )
7153+ np .testing .assert_allclose (xlim , res_xlim , atol = 1e-16 )
7154+ np .testing .assert_allclose (ylim , res_ylim , atol = 1e-16 )
7155+
7156+
71217157def test_gettightbbox_ignore_nan ():
71227158 fig , ax = plt .subplots ()
71237159 remove_ticks_and_titles (fig )
0 commit comments