|
| 1 | +import numpy as np |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +from matplotlib.testing.decorators import check_figures_equal |
| 4 | +from matplotview import view, inset_zoom_axes |
| 5 | + |
| 6 | +# Tolerance needed because the way the auto-zoom axes handles images is |
| 7 | +# entirely different, leading to a slightly different result. |
| 8 | +@check_figures_equal(tol=3) |
| 9 | +def test_auto_zoom_inset(fig_test, fig_ref): |
| 10 | + np.random.seed(1) |
| 11 | + im_data = np.random.rand(30, 30) |
| 12 | + |
| 13 | + # Test Case... |
| 14 | + ax_test = fig_test.gca() |
| 15 | + ax_test.plot([i for i in range(10)], "r") |
| 16 | + ax_test.add_patch(plt.Circle((3, 3), 1, ec="black", fc="blue")) |
| 17 | + ax_test.imshow(im_data, origin="lower", cmap="Blues", alpha=0.5, |
| 18 | + interpolation="nearest") |
| 19 | + axins_test = inset_zoom_axes(ax_test, [0.5, 0.5, 0.48, 0.48]) |
| 20 | + axins_test.set_linescaling(False) |
| 21 | + axins_test.set_xlim(1, 5) |
| 22 | + axins_test.set_ylim(1, 5) |
| 23 | + ax_test.indicate_inset_zoom(axins_test, edgecolor="black") |
| 24 | + |
| 25 | + # Reference |
| 26 | + ax_ref = fig_ref.gca() |
| 27 | + ax_ref.plot([i for i in range(10)], "r") |
| 28 | + ax_ref.add_patch(plt.Circle((3, 3), 1, ec="black", fc="blue")) |
| 29 | + ax_ref.imshow(im_data, origin="lower", cmap="Blues", alpha=0.5, |
| 30 | + interpolation="nearest") |
| 31 | + axins_ref = ax_ref.inset_axes([0.5, 0.5, 0.48, 0.48]) |
| 32 | + axins_ref.set_xlim(1, 5) |
| 33 | + axins_ref.set_ylim(1, 5) |
| 34 | + axins_ref.plot([i for i in range(10)], "r") |
| 35 | + axins_ref.add_patch(plt.Circle((3, 3), 1, ec="black", fc="blue")) |
| 36 | + axins_ref.imshow(im_data, origin="lower", cmap="Blues", alpha=0.5, |
| 37 | + interpolation="nearest") |
| 38 | + ax_ref.indicate_inset_zoom(axins_ref, edgecolor="black") |
| 39 | + |
0 commit comments