Skip to content

Commit 1c642e0

Browse files
timtreisclaude
andcommitted
Use literal color for outlines when outline_color is not set
When color is a literal (e.g., 'white') and no outline_color is given, use the literal color for outlines. This fixes the invisible-outline case from issue #462 where color='white' with outline_alpha=1 produced white outlines on a white background because the data-driven path was used instead. When color is a column name (data-driven), outlines still inherit per-label colors from the colormap. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9407fae commit 1c642e0

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/spatialdata_plot/pl/render.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,14 @@ def _draw_labels(
13791379
cax = ax.add_image(_cax)
13801380
return cax # noqa: RET504
13811381

1382+
# When color is a literal (col_for_color is None) and no explicit outline_color,
1383+
# use the literal color for outlines so they are visible (e.g., color='white' on
1384+
# a dark background). When color is data-driven, outlines inherit the per-label
1385+
# colors from label2rgb (outline_color stays None).
1386+
effective_outline_color = render_params.outline_color
1387+
if effective_outline_color is None and col_for_color is None and render_params.color is not None:
1388+
effective_outline_color = render_params.color
1389+
13821390
# default case: no contour, just fill
13831391
# since contour_px is passed to skimage.morphology.erosion to create the contour,
13841392
# any border thickness is only within the label, not outside. Therefore, the case
@@ -1395,7 +1403,7 @@ def _draw_labels(
13951403
seg_erosionpx=render_params.contour_px,
13961404
seg_boundaries=True,
13971405
alpha=render_params.outline_alpha,
1398-
outline_color=render_params.outline_color,
1406+
outline_color=effective_outline_color,
13991407
)
14001408
alpha_to_decorate_ax = render_params.outline_alpha
14011409

@@ -1409,7 +1417,7 @@ def _draw_labels(
14091417
seg_erosionpx=render_params.contour_px,
14101418
seg_boundaries=True,
14111419
alpha=render_params.outline_alpha,
1412-
outline_color=render_params.outline_color,
1420+
outline_color=effective_outline_color,
14131421
)
14141422

14151423
# pass the less-transparent _cax for the legend

0 commit comments

Comments
 (0)