Skip to content

Feature/outline color for labels#525

Open
MeyerBender wants to merge 11 commits intoscverse:mainfrom
MeyerBender:feature/outline_color_for_labels
Open

Feature/outline color for labels#525
MeyerBender wants to merge 11 commits intoscverse:mainfrom
MeyerBender:feature/outline_color_for_labels

Conversation

@MeyerBender
Copy link
Contributor

This addresses two previous issues with rendering labels:

  1. Users can now set the color of the outline with the outline_color argument, similar to how they could in render_shapes(), see Ability to change color of the border of labels #462
  2. Fixes color leak when plotting outlines only in render_labels, see Color leak when outline_alpha=1 and full_alpha=0 #461

Example code to see both changes in action:

import spatialdata as sd
import spatialdata_plot
from spatialdata.datasets import blobs

sdata = blobs()
sdata.pl.render_images('blobs_image', channel=0).pl.render_labels('blobs_labels', outline_alpha=1, fill_alpha=0, outline_color='white').pl.show()

@MeyerBender
Copy link
Contributor Author

@timtreis Naive question but I can't find where to download the artifacts to fix the tests, is this a permission issue or am I missing something?

@LucaMarconato
Copy link
Member

@MeyerBender artifacts can be downloaded from the Actions page, for instance here: https://github.com/scverse/spatialdata-plot/actions/runs/20439596502?pr=526

Please find more info here: https://github.com/scverse/spatialdata-plot/blob/main/docs/contributing.md. Let me know if some questions are still open and not covered by the contribution guide.

@MeyerBender
Copy link
Contributor Author

MeyerBender commented Jan 14, 2026

Thanks @LucaMarconato! With my current implementation, it is only possible to specify a colorlike, but not a feature (like "area"). I think it would be good to merge #497 first, and then add my code on top of that.

MeyerBender and others added 6 commits March 11, 2026 15:46
- Simplify outline_color type for labels to ColorLike | None (no tuple)
- Store as Color | None in LabelsRenderParams (consistent with shapes)
- Add proper type annotation to _draw_labels
- Simplify _map_color_seg boundary rendering: build clean RGBA image
  with outline_color on the eroded ring, transparent elsewhere
- Remove duplicate matplotlib.colors import (mcolors → colors)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move the label2rgb call below the seg_boundaries early return so it is
not computed when only the outline ring is needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timtreis timtreis force-pushed the feature/outline_color_for_labels branch from 7d8202e to 3e2d6a1 Compare March 11, 2026 15:30
Add baselines for new outline_color tests and update existing baselines
that changed due to the find_boundaries → solid outline_color rewrite
and square → footprint_rectangle migration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov-commenter
Copy link

codecov-commenter commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.96%. Comparing base (4fe68de) to head (9485058).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #525      +/-   ##
==========================================
- Coverage   84.01%   83.96%   -0.05%     
==========================================
  Files           9        9              
  Lines        2608     2626      +18     
==========================================
+ Hits         2191     2205      +14     
- Misses        417      421       +4     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/basic.py 91.63% <ø> (ø)
src/spatialdata_plot/pl/render.py 89.01% <100.00%> (+0.06%) ⬆️
src/spatialdata_plot/pl/render_params.py 90.35% <100.00%> (+0.04%) ⬆️
src/spatialdata_plot/pl/utils.py 79.24% <100.00%> (-0.08%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

timtreis and others added 4 commits March 12, 2026 12:13
…or is None

Only apply uniform outline_color when explicitly set. When None (default),
use the data-driven colors from label2rgb on the eroded ring — preserving
the existing behavior for continuous/categorical outline coloring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 scverse#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>
Use contour_px=10 for thicker outlines and blue instead of white for
the fill+outline test so the outline is clearly distinguishable in
baseline images.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timtreis
Copy link
Member

Hey @MeyerBender, I merged #497 and updated your PR accordingly. Could you verify that it matches the behaviour you intended?

@MeyerBender
Copy link
Contributor Author

Hi @timtreis, this looks great, thanks a lot! As a sidenote, running pl.render_labels('blobs_labels', outline_alpha=1) without specifying a color sets a random color for each cell, which might be confusing. I agree with your comment in the other PR that using just one color would be more sensible in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants