scverse / scverse/spatialdata-plot

Outline color palette is ignored in `render_shapes` if no color is passed

Offen
#777 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Python
Sterne
86
Forks
21
Ø Merge
14 Std. 50 Min.
Gemergte PRs (30 T.)
3

Beschreibung

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)
Image Image
Versions

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne am render_shapes-Einstiegspunkt und führe die bereitgestellte Reproduktion aus, wobei du color= mit outline_color= und fill_alpha=0 vergleichst. Verfolge, wie jedes Argument die kategoriale Palette auflöst; fertig ist es, wenn outline_color= die bereitgestellte Palette statt der standardmäßigen tab10-Farben verwendet, während das bestehende Verhalten von color= unverändert bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.