Skip to content

Commit 31e6a76

Browse files
timtreisclaude
andcommitted
Implement frameon parameter and deprecate fig in show()
frameon=False now calls ax.axis("off") matching scanpy's behavior. The fig parameter emits a deprecation warning (it was silently ignored); the warning is suppressed when ax is a Sequence since fig is still required in that multi-panel path. Closes #204 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e54c74f commit 31e6a76

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

src/spatialdata_plot/pl/basic.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import contextlib
44
import sys
55
from collections import OrderedDict
6-
from collections.abc import Callable
6+
from collections.abc import Callable, Sequence
77
from copy import deepcopy
88
from pathlib import Path
99
from typing import Any, Literal, cast
@@ -938,6 +938,13 @@ def show(
938938
show,
939939
)
940940

941+
if fig is not None and not isinstance(ax, Sequence):
942+
logger.warning(
943+
"The `fig` parameter is deprecated and will be removed in a future version. "
944+
"To use a custom figure, create axes from it and pass them via `ax` instead: "
945+
"`ax = fig.add_subplot(111)`."
946+
)
947+
941948
sdata = self._copy()
942949

943950
# Evaluate execution tree for plotting
@@ -1242,6 +1249,8 @@ def _draw_colorbar(
12421249
raise IndexError("The number of titles must match the number of coordinate systems.") from e
12431250
ax.set_title(t)
12441251
ax.set_aspect("equal")
1252+
if fig_params.frameon is False:
1253+
ax.axis("off")
12451254

12461255
extent = get_extent(
12471256
sdata,

tests/pl/test_show.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import matplotlib
44
import matplotlib.pyplot as plt
55
import scanpy as sc
6+
from matplotlib.figure import Figure
67
from spatialdata import SpatialData
78

89
import spatialdata_plot # noqa: F401
10+
from spatialdata_plot._logging import logger, logger_no_warns, logger_warns
911
from tests.conftest import DPI, PlotTester, PlotTesterMeta
1012

1113
sc.pl.set_rcParams_defaults()
@@ -40,3 +42,54 @@ def test_plt_show_when_ax_provided_and_show_true(self, sdata_blobs: SpatialData)
4042
sdata_blobs.pl.render_images(element="blobs_image").pl.show(ax=ax, show=True)
4143
mock_show.assert_called_once()
4244
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

Comments
 (0)