Skip to content

Commit 2bdd685

Browse files
timtreisclaude
andcommitted
Honor RGBA alpha in render_labels, aligning with points/shapes behavior
Change fill_alpha default from 0.4 to None so that _type_check_params can extract the alpha from an RGBA color tuple, matching how points and shapes already handle this. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9e4e3c0 commit 2bdd685

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/spatialdata_plot/pl/basic.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ def render_labels(
640640
norm: Normalize | None = None,
641641
na_color: ColorLike | None = "default",
642642
outline_alpha: float | int = 0.0,
643-
fill_alpha: float | int = 0.4,
643+
fill_alpha: float | int | None = None,
644644
scale: str | None = None,
645645
colorbar: bool | str | None = "auto",
646646
colorbar_params: dict[str, object] | None = None,
@@ -689,8 +689,9 @@ def render_labels(
689689
won't be shown.
690690
outline_alpha : float | int, default 0.0
691691
Alpha value for the outline of the labels. Invisible by default.
692-
fill_alpha : float | int, default 0.4
693-
Alpha value for the fill of the labels.
692+
fill_alpha : float | int | None, optional
693+
Alpha value for the fill of the labels. By default, it is set to 0.4 or, if a color is given that implies
694+
an alpha, that value is used for `fill_alpha`.
694695
scale : str | None
695696
Influences the resolution of the rendering. Possibilities for setting this parameter:
696697
1) None (default). The image is rasterized to fit the canvas size. For multiscale images, the best scale

src/spatialdata_plot/pl/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,9 @@ def _type_check_params(param_dict: dict[str, Any], element_type: str) -> dict[st
22702270
elif element_type == "shapes":
22712271
# set default fill_alpha for shapes if not given by user explicitly or implicitly (as part of color)
22722272
param_dict["fill_alpha"] = 1.0
2273+
elif element_type == "labels":
2274+
# set default fill_alpha for labels if not given by user explicitly or implicitly (as part of color)
2275+
param_dict["fill_alpha"] = 0.4
22732276

22742277
cmap = param_dict.get("cmap")
22752278
palette = param_dict.get("palette")
@@ -2427,7 +2430,7 @@ def _validate_label_render_params(
24272430
element: str | None,
24282431
cmap: list[Colormap | str] | Colormap | str | None,
24292432
color: ColorLike | None,
2430-
fill_alpha: float | int,
2433+
fill_alpha: float | int | None,
24312434
contour_px: int | None,
24322435
groups: list[str] | str | None,
24332436
palette: list[str] | str | None,

0 commit comments

Comments
 (0)