| 8452 | |
| 8453 | |
| 8454 | def test_limits_after_scroll_zoom(): |
| 8455 | fig, ax = plt.subplots() |
| 8456 | # |
| 8457 | xlim = (-0.5, 0.5) |
| 8458 | ylim = (-1, 2) |
| 8459 | ax.set_xlim(xlim) |
| 8460 | ax.set_ylim(ymin=ylim[0], ymax=ylim[1]) |
| 8461 | # This is what scroll zoom calls: |
| 8462 | # Zoom with factor 1, small numerical change |
| 8463 | ax._set_view_from_bbox((200, 200, 1.)) |
| 8464 | np.testing.assert_allclose(xlim, ax.get_xlim(), atol=1e-16) |
| 8465 | np.testing.assert_allclose(ylim, ax.get_ylim(), atol=1e-16) |
| 8466 | |
| 8467 | # Zoom in |
| 8468 | ax._set_view_from_bbox((200, 200, 2.)) |
| 8469 | # Hard-coded values |
| 8470 | new_xlim = (-0.3790322580645161, 0.12096774193548387) |
| 8471 | new_ylim = (-0.40625, 1.09375) |
| 8472 | |
| 8473 | res_xlim = ax.get_xlim() |
| 8474 | res_ylim = ax.get_ylim() |
| 8475 | np.testing.assert_allclose(res_xlim[1] - res_xlim[0], 0.5) |
| 8476 | np.testing.assert_allclose(res_ylim[1] - res_ylim[0], 1.5) |
| 8477 | np.testing.assert_allclose(new_xlim, res_xlim, atol=1e-16) |
| 8478 | np.testing.assert_allclose(new_ylim, res_ylim) |
| 8479 | |
| 8480 | # Zoom out, should be same as before, except for numerical issues |
| 8481 | ax._set_view_from_bbox((200, 200, 0.5)) |
| 8482 | res_xlim = ax.get_xlim() |
| 8483 | res_ylim = ax.get_ylim() |
| 8484 | np.testing.assert_allclose(res_xlim[1] - res_xlim[0], 1) |
| 8485 | np.testing.assert_allclose(res_ylim[1] - res_ylim[0], 3) |
| 8486 | np.testing.assert_allclose(xlim, res_xlim, atol=1e-16) |
| 8487 | np.testing.assert_allclose(ylim, res_ylim, atol=1e-16) |
| 8488 | |
| 8489 | |
| 8490 | def test_gettightbbox_ignore_nan(): |