Skip to content

Commit 2f3d4a0

Browse files
committed
Tighten legend_params comments and docstring
1 parent adeb876 commit 2f3d4a0

3 files changed

Lines changed: 5 additions & 18 deletions

File tree

src/spatialdata_plot/pl/basic.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,9 @@ def show(
967967
e.g. ``{"location": "lower right", "color": "white", "length_fraction": 0.25}``.
968968
See the matplotlib-scalebar documentation for the full list of options.
969969
legend_params : dict[str, Any] | None
970-
Bundled legend options. Mirrors ``colorbar_params`` / ``scalebar_params``. Accepted keys:
971-
``location`` (canonical, alias ``loc`` accepted to match
972-
:class:`matplotlib.legend.Legend`), ``fontsize``, ``fontweight``, ``fontoutline``,
973-
``na_in_legend``. When a key is set both as a flat kwarg (e.g. ``legend_fontsize=12``)
974-
and inside this dict, the dict value wins. Unknown keys raise ``ValueError`` to surface
975-
typos early.
970+
Bundled legend options; overrides the matching ``legend_*`` flat kwargs. Accepted keys:
971+
``location`` (or ``loc``), ``fontsize``, ``fontweight``, ``fontoutline``,
972+
``na_in_legend``. Unknown keys raise ``ValueError``.
976973
977974
Returns
978975
-------
@@ -1140,15 +1137,10 @@ def show(
11401137
scalebar_units=scalebar_units,
11411138
scalebar_kwargs=scalebar_params,
11421139
)
1143-
# Merge dict-form legend_params over the flat legend_* kwargs (dict wins). Unknown keys
1144-
# have already been rejected by _validate_show_parameters; treat the dict as authoritative.
1145-
# Note: matplotlib.legend.Legend uses `loc`, while Figure.colorbar and matplotlib_scalebar
1146-
# use `location`. We accept both spellings so legend_params reads consistently with
1147-
# colorbar_params / scalebar_params; `location` is the canonical name and wins if both are
1148-
# passed.
11491140
if legend_params:
11501141
legend_fontsize = legend_params.get("fontsize", legend_fontsize)
11511142
legend_fontweight = legend_params.get("fontweight", legend_fontweight)
1143+
# `loc` is matplotlib.Legend's native key; `location` aligns with colorbar/scalebar.
11521144
legend_loc = legend_params.get("location", legend_params.get("loc", legend_loc))
11531145
legend_fontoutline = legend_params.get("fontoutline", legend_fontoutline)
11541146
na_in_legend = legend_params.get("na_in_legend", na_in_legend)

src/spatialdata_plot/pl/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,9 +2277,7 @@ def _validate_show_parameters(
22772277
if legend_params is not None:
22782278
if not isinstance(legend_params, dict):
22792279
raise TypeError("Parameter 'legend_params' must be a dictionary or None.")
2280-
# `location` is the canonical name (matches colorbar_params / scalebar_params); `loc` is
2281-
# accepted as an alias because that is what matplotlib.legend.Legend natively uses, so
2282-
# copy-paste from matplotlib examples keeps working.
2280+
# `loc` is matplotlib.Legend's native key; `location` aligns with colorbar_params / scalebar_params.
22832281
allowed_legend_keys = {"loc", "location", "fontsize", "fontweight", "fontoutline", "na_in_legend"}
22842282
unknown = set(legend_params) - allowed_legend_keys
22852283
if unknown:

tests/pl/test_show.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,6 @@ def test_legend_params_validation_rejects_bad_inputs(sdata_blobs: SpatialData, k
328328

329329
def test_legend_params_location_alias_for_loc(sdata_blobs: SpatialData):
330330
"""legend_params accepts both 'location' (canonical) and 'loc' (matplotlib-native alias)."""
331-
# Both spellings reach LegendParams.legend_loc; verify by confirming neither raises and the
332-
# canonical 'location' takes precedence when both are passed (the alias resolution is a small
333-
# consequence of mirroring colorbar_params / scalebar_params naming).
334331
sdata_blobs.pl.render_shapes(element="blobs_circles").pl.show(
335332
legend_params={"loc": "upper right"}, return_ax=True, show=False
336333
)

0 commit comments

Comments
 (0)