Outline color palette is ignored in `render_shapes` if no color is passed
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python
- Domain
- data-visualization
Research direction
Start at the render_shapes entry point and run the provided reproduction comparing color= with outline_color= and fill_alpha=0. Trace how each argument resolves the categorical palette; done means outline_color= uses the supplied palette instead of default tab10 colors, while the existing color= behavior remains unchanged.
Written by the indexing model from the issue text.
Description
Report
When coloring shapes by a categorical column using only outline_color= (with fill_alpha=0), the palette dict is silently ignored and matplotlib's default tab10 colors are used instead. Passing the same column/palette via color= works correctly.
Environment: spatialdata 0.8.0, spatialdata-plot 0.4.2
Expected: outline_color= should resolve palette the same way color= does.
Workaround: pass the column to both color= and outline_color= (keeping fill_alpha=0).
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import anndata as ad
import spatialdata as sd
import spatialdata_plot
from spatialdata.models import TableModel
sdata = sd.datasets.blobs()
shapes_key = "blobs_polygons" # not annotated by the default blobs table
n = sdata[shapes_key].shape[0]
palette = {
"EL": "#cba02c", "ES": "#ebc84f", "RL": "#0272b2", "RM": "#5799d1", "RS": "#9dcbec",
}
labels = pd.Categorical(list(palette.keys())[:n], categories=list(palette.keys()))
# Table annotating blobs_polygons with our categorical color column
obs = pd.DataFrame({"instance_id": np.arange(n), "region": pd.Categorical(["blobs_polygons"] * n)})
obs.index = obs.index.astype(str)
table = TableModel.parse(
ad.AnnData(X=np.zeros((n, 1)), obs=obs),
region=["blobs_polygons"], region_key="region", instance_key="instance_id",
)
sdata.tables["t"] = table
sdata["t"].obs["celltype"] = labels
# Works: palette correctly maps to fill colors
fig, ax = plt.subplots()
sdata.pl.render_shapes(shapes_key, color="celltype", palette=palette, table_name="t").pl.show(ax=ax)
fig.savefig("color_works.png", dpi=100)
# Bug: palette is ignored, falls back to default tab10 colors
fig, ax = plt.subplots()
sdata.pl.render_shapes(
shapes_key, outline_color="celltype", palette=palette, fill_alpha=0,
outline_width=1.5, table_name="t",
).pl.show(ax=ax)
fig.savefig("outline_color_bug.png", dpi=100)
Versions
- Dominant language
- Python
- Stars
- 86
- Forks
- 21
- Avg merge
- 14h 50m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from scverse/spatialdata-plot
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
scverse/spatialdata-plot#775 ·
-
`pl.show()` leading to `ValueError` due to mismatch between number of axes and number of panels Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
scverse/spatialdata-plot#749 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
scverse/spatialdata-plot#747 ·
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
scverse/spatialdata-plot#677 ·
-
enhancement priority: medium utils :wrench:
Difficulty 3/5 1-2 days Newbie friendliness 68/100
scverse/spatialdata-plot#632 ·
All issues in scverse/spatialdata-plot
Similar issues
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
DiamondLightSource/dodal#2211 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
openml/openml-python#1749 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sipyourdrink-ltd/bernstein#6191 ·