scverse / scverse/spatialdata-plot

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

Ouverte
#777 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug
Langage dominant
Python
Étoiles
86
Forks
21
Merge moyen
14 h 50 min
PR mergées (30 j)
3

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez au point d’entrée render_shapes et exécutez la reproduction fournie en comparant color= à outline_color= et fill_alpha=0. Suivez la manière dont chaque argument résout la palette catégorielle ; le travail est terminé lorsque outline_color= utilise la palette fournie au lieu des couleurs tab10 par défaut, tandis que le comportement existant de color= reste inchangé.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
data-visualization
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Active
Clarté
Plutôt claire
Accessibilité débutants
68/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.