scverse / scverse/spatialdata-plot
Outline color palette is ignored in `render_shapes` if no color is passed
未关闭
还没有人认领这个 Issue。
bug
- 主要语言
- Python
- 星标
- 86
- 派生
- 21
- 平均合并
- 14 小时 50 分钟
- 30 天内合并 PR
- 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)
Versions
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 render_shapes 入口点开始,运行提供的复现,比较 color= 与 outline_color= 和 fill_alpha=0。跟踪每个参数如何解析分类调色板;完成标准是 outline_color= 使用提供的调色板,而不是默认的 tab10 颜色,同时现有的 color= 行为保持不变。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100