scverse / scverse/spatialdata-plot

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

オープン
#777 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
Python
スター
86
フォーク
21
平均マージ
14時間 50分
マージ済み PR(30日)
3

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

render_shapes エントリポイントから開始し、color= と outline_color= および fill_alpha=0 を比較しながら、提供されている再現手順を実行します。各引数がカテゴリカルパレットをどのように解決するかを追跡します。完了条件は、outline_color= がデフォルトの tab10 カラーではなく指定されたパレットを使用し、既存の color= の動作が変わらないことです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
data-visualization
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
68/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。