Skip to content

Commit ba7f037

Browse files
timtreisclaude
andcommitted
Filter non-matching elements by default when groups is specified
Previously, non-matching elements were shown in grey (na_color) by default when using groups. Now they are filtered out entirely, which is the more intuitive behavior. To show non-matching elements, set na_color explicitly (e.g., na_color="red"). This applies to shapes and points only (labels are raster-based and cannot be filtered). Baseline images removed for regeneration — existing groups tests will produce different output with the new default. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8f68a73 commit ba7f037

13 files changed

+30
-28
lines changed

src/spatialdata_plot/pl/basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ def render_shapes(
213213
`fill_alpha` will overwrite the value present in the cmap.
214214
groups : list[str] | str | None
215215
When using `color` and the key represents discrete labels, `groups` can be used to show only a subset of
216-
them. Other values are set to NA. When ``na_color=None``, non-matching elements are filtered out entirely
217-
instead of rendered invisibly (shapes and points only; labels are raster-based and cannot be filtered).
216+
them. By default, non-matching elements are filtered out entirely (shapes and points only; labels are
217+
raster-based and cannot be filtered). To show non-matching elements, set ``na_color`` explicitly.
218218
If element is None, broadcasting behaviour is attempted (use the same values for all elements).
219219
palette : list[str] | str | None
220220
Palette for discrete annotations. List of valid color names that should be used for the categories. Must

src/spatialdata_plot/pl/render.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,10 @@ def _render_shapes(
272272

273273
values_are_categorical = color_source_vector is not None
274274

275-
# When groups are specified and na_color is fully transparent (na_color=None),
276-
# filter out non-matching elements instead of showing them as invisible geometry.
277-
if groups is not None and values_are_categorical and render_params.cmap_params.na_color.alpha == "00":
275+
# When groups are specified, filter out non-matching elements by default.
276+
# Only show non-matching elements if the user explicitly sets na_color.
277+
_na = render_params.cmap_params.na_color
278+
if groups is not None and values_are_categorical and (_na.default_color_set or _na.alpha == "00"):
278279
keep, color_source_vector, color_vector = _filter_groups_transparent_na(
279280
groups, color_source_vector, color_vector
280281
)
@@ -883,9 +884,10 @@ def _render_points(
883884
if added_color_from_table and col_for_color is not None:
884885
_reparse_points(sdata_filt, element, points_pd_with_color, transformation_in_cs, coordinate_system)
885886

886-
# When groups are specified and na_color is fully transparent (na_color=None),
887-
# filter out non-matching points instead of rendering invisible geometry.
888-
if groups is not None and color_source_vector is not None and render_params.cmap_params.na_color.alpha == "00":
887+
# When groups are specified, filter out non-matching elements by default.
888+
# Only show non-matching elements if the user explicitly sets na_color.
889+
_na = render_params.cmap_params.na_color
890+
if groups is not None and color_source_vector is not None and (_na.default_color_set or _na.alpha == "00"):
889891
keep, color_source_vector, color_vector = _filter_groups_transparent_na(
890892
groups, color_source_vector, color_vector
891893
)
-37.1 KB
Binary file not shown.
-48.9 KB
Binary file not shown.
-48.5 KB
Binary file not shown.
-46 KB
Binary file not shown.
-54 KB
Binary file not shown.
Binary file not shown.
-26 KB
Binary file not shown.
-26.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)