|
3 | 3 | import matplotlib |
4 | 4 | import matplotlib.pyplot as plt |
5 | 5 | import scanpy as sc |
| 6 | +from matplotlib.figure import Figure |
6 | 7 | from spatialdata import SpatialData |
7 | 8 |
|
8 | 9 | import spatialdata_plot # noqa: F401 |
| 10 | +from spatialdata_plot._logging import logger, logger_no_warns, logger_warns |
9 | 11 | from tests.conftest import DPI, PlotTester, PlotTesterMeta |
10 | 12 |
|
11 | 13 | sc.pl.set_rcParams_defaults() |
@@ -40,3 +42,54 @@ def test_plt_show_when_ax_provided_and_show_true(self, sdata_blobs: SpatialData) |
40 | 42 | sdata_blobs.pl.render_images(element="blobs_image").pl.show(ax=ax, show=True) |
41 | 43 | mock_show.assert_called_once() |
42 | 44 | plt.close("all") |
| 45 | + |
| 46 | + def test_frameon_false_hides_axes_decorations(self, sdata_blobs: SpatialData): |
| 47 | + """frameon=False should turn off axes decorations (regression for #204).""" |
| 48 | + ax = sdata_blobs.pl.render_images(element="blobs_image").pl.show(frameon=False, return_ax=True, show=False) |
| 49 | + assert not ax.axison |
| 50 | + plt.close("all") |
| 51 | + |
| 52 | + def test_frameon_none_keeps_axes_decorations(self, sdata_blobs: SpatialData): |
| 53 | + """Default frameon=None should keep axes decorations visible.""" |
| 54 | + ax = sdata_blobs.pl.render_images(element="blobs_image").pl.show(frameon=None, return_ax=True, show=False) |
| 55 | + assert ax.axison |
| 56 | + plt.close("all") |
| 57 | + |
| 58 | + def test_title_empty_string_suppresses_title(self, sdata_blobs: SpatialData): |
| 59 | + """title='' should suppress the default coordinate system title (regression for #204).""" |
| 60 | + ax = sdata_blobs.pl.render_images(element="blobs_image").pl.show(title="", return_ax=True, show=False) |
| 61 | + assert ax.get_title() == "" |
| 62 | + plt.close("all") |
| 63 | + |
| 64 | + |
| 65 | +def test_fig_parameter_emits_deprecation_warning(sdata_blobs: SpatialData, caplog): |
| 66 | + """Passing fig= should emit a deprecation warning (regression for #204).""" |
| 67 | + fig = Figure() |
| 68 | + with logger_warns(caplog, logger, match="The `fig` parameter is deprecated"): |
| 69 | + sdata_blobs.pl.render_images(element="blobs_image").pl.show(fig=fig, show=False) |
| 70 | + plt.close("all") |
| 71 | + |
| 72 | + |
| 73 | +def test_fig_parameter_default_no_warning(sdata_blobs: SpatialData, caplog): |
| 74 | + """Not passing fig= should not emit a deprecation warning.""" |
| 75 | + with logger_no_warns(caplog, logger, match="The `fig` parameter is deprecated"): |
| 76 | + sdata_blobs.pl.render_images(element="blobs_image").pl.show(show=False) |
| 77 | + plt.close("all") |
| 78 | + |
| 79 | + |
| 80 | +def test_fig_parameter_no_warning_with_ax_list(get_sdata_with_multiple_images, caplog): |
| 81 | + """Passing fig= with a list of axes should not warn (fig is still required there).""" |
| 82 | + sdata = get_sdata_with_multiple_images("two") |
| 83 | + fig, axs = plt.subplots(1, 2) |
| 84 | + with logger_no_warns(caplog, logger, match="The `fig` parameter is deprecated"): |
| 85 | + sdata.pl.render_images().pl.show(fig=fig, ax=list(axs), show=False) |
| 86 | + plt.close("all") |
| 87 | + |
| 88 | + |
| 89 | +def test_frameon_false_multi_panel(get_sdata_with_multiple_images): |
| 90 | + """frameon=False should apply to all panels in a multi-panel plot (regression for #204).""" |
| 91 | + sdata = get_sdata_with_multiple_images("two") |
| 92 | + axs = sdata.pl.render_images().pl.show(frameon=False, return_ax=True, show=False) |
| 93 | + for ax in axs: |
| 94 | + assert not ax.axison |
| 95 | + plt.close("all") |
0 commit comments