You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can we manually set an outline color for all labels? #202
I want to plot contours only, so that I can overlay multiple labels without them occluding each other.
I want to plot all contours of a labels image with a uniform color, so that I can distinguish labels images (colorize by element, not by annotation).
Example
fromspatialdataimportSpatialDatafromspatialdata.modelsimportLabels2DModelimportnumpyasnpimportspatialdata_plot# Two labelsarray1=np.zeros((10, 10), dtype=np.uint16)
array1[1:4, 1:4] =1array1[4:9, 4:9] =2# One label intersecting a label in array1array2=np.zeros((10, 10), dtype=np.uint16)
array2[2:7, 6:9] =1sdata=SpatialData(
labels={
"labels1": Labels2DModel.parse(array1, dims=("y", "x")),
"labels2": Labels2DModel.parse(array2, dims=("y", "x")),
}
)
sdata.pl.render_labels(
elements="labels1",
contour_px=3, # Surprising! contour_px=1 does not render at alloutline=True,
outline_alpha=1.0,
# outline_color="red", # Not yet existingfill_alpha=0.0,
).pl.render_labels(
elements="labels2",
contour_px=3,
outline=True,
outline_alpha=1.0,
# outline_color="green", # Not yet existingfill_alpha=0.0,
).pl.show(figsize=(2,2))
Actual:
Desired:
Both cmap and palette affect the fill, not the contour.
I don't know whether there are use cases for having the outline color by annotation value.
Analogously, one could want pass an actual color name `color="red" (instead of an obs column/ var name) to apply a uniform fill color to all labels.
Issues
Labels rendering currently requires the region to be annotated in the table, or no table at all. This is because _render_labels selects labels to render based on the table. However, a SpatialData with labels only is perfectly valid and there can be interest in visualizing them.
Adding fill_alpha=1.0 to above examples should render some default, but raises an error. This is because _map_color_seg is passed a SpatialImage instead of a Numpy array (seg=labels.values).
My request was to specify an outline color per labels element, that is uniform to all label values of that element. It was already possible enable outline without fill, but the outline is always black.
From the comment, I couldn't find anything that solves this issue (two render_labels commands, `na_color="green"``).
I think we would need a separate argument like outline_color that can be set to values other than black.
Activity
aeisenbarth commentedon Dec 14, 2023
Use case
Example
Actual:

Desired:

Both
cmapandpaletteaffect the fill, not the contour.I don't know whether there are use cases for having the outline color by annotation value.
Analogously, one could want pass an actual color name `color="red" (instead of an obs column/ var name) to apply a uniform fill color to all labels.
Issues
Labels rendering currently requires the region to be annotated in the table, or no table at all. This is because
_render_labelsselects labels to render based on the table. However, a SpatialData with labels only is perfectly valid and there can be interest in visualizing them.Adding
fill_alpha=1.0to above examples should render some default, but raises an error. This is because _map_color_seg is passed a SpatialImage instead of a Numpy array (seg=labels.values).timtreis commentedon Aug 29, 2024
Hey @aeisenbarth, does this comment do what you wanted do describe here:
#252 (comment)
?
aeisenbarth commentedon Sep 1, 2024
My request was to specify an outline color per labels element, that is uniform to all label values of that element. It was already possible enable outline without fill, but the outline is always black.
From the comment, I couldn't find anything that solves this issue (two
render_labelscommands, `na_color="green"``).I think we would need a separate argument like
outline_colorthat can be set to values other than black.timtreis commentedon Mar 29, 2026
Finally fixed with #525