scverse / scverse/spatialdata-plot

Additive RGB color blending for render_shapes / render_labels (and render_points)

未关闭
#677 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
86
派生
21
平均合并
14 小时 50 分钟
30 天内合并 PR
3

描述

Motivation

Spun out from #321 (the thread there mixes two unrelated asks — this issue is the second one, originally raised by @brainfo).

`render_images` already supports multi-channel additive compositing: you pass several channels with per-channel colormaps and they blend into a single RGB image, mirroring napari / ImageJ / FIJI for fluorescence microscopy. The same idiom is useful for sequencing-based spatial data, where a user wants to visualize co-expression of 2–3 genes per cell/spot/region on a single axis — red for gene A, green for gene B, blue for gene C, additively blended so co-expressing cells appear yellow/cyan/white.

Today this requires manual post-processing (the user in #321 mentions doing it in Illustrator).

Proposed API

Mirror the existing `render_images` multi-channel convention by letting `color` accept a list of obs/var columns on `render_shapes`, `render_labels`, and `render_points`:

```python
sdata.pl.render_shapes(
color=["Sox2", "Pax6", "Tbr2"],
palette=["red", "green", "blue"], # one color per channel
channels_as_legend=True,
).pl.show()

sdata.pl.render_labels(
color=["Sox2", "Pax6"],
palette=["red", "green"],
).pl.show()

sdata.pl.render_points(
color=["Sox2", "Pax6"],
).pl.show()
```

Output: a single axis (no multi-panel grid). Each shape / label / point gets one composited color derived from its per-column values blended via per-channel colormaps, identical in spirit to the additive multi-channel path already in `render_images`.

Why this is feasible

  • The additive-blending machinery already exists in `pl/render.py` for the multi-channel image path (see `render_images` branches 2A/2B/2C). The same per-channel cmap + sum + clip logic applies.
  • Single-axis output sidesteps the hierarchy-of-axes complexity that made multi-panel `color=[...]` (the other ask from #321) undesirable.
  • `channels_as_legend` already exists for `render_images`; can extend.

Scope

  • In scope: 2–3-column color lists on `render_shapes`, `render_labels`, `render_points`. Per-channel `cmap` or `palette`. Additive blend on a single axis.
  • Out of scope (defer or decline):
    • Multi-panel grids (`sc.pl.umap`-style) — already declined in #321.
    • Arbitrary blend modes beyond additive — start with the existing `render_images` semantics.
    • PCA-based or learned color reductions for >3 channels.

Edge cases to design for

  • Length mismatch between `color` list and `palette` list.
  • Mixing categorical and continuous columns in the same `color` list (probably reject with a clear error).
  • NaN handling per column (skip vs zero vs error — likely error, matching the recent `render_images` NaN rejection).
  • Per-column `norm` / `vmin` / `vmax` — accept a list, parallel to the per-channel `norm` already supported on `render_images`.
  • `groups` semantics when `color` is a list — likely ignored with a warning.

Relation to #321

#321 conflates two asks under "plotting multiple genes":

  1. Multi-panel grid for several genes — declined; possibly hosted in a future Squidpy 2.0 wrapper.
  2. Single-axis additive blend for co-expression visualization — this issue.

The documentation sub-tasks in #321 (`save`, `ncols` on `pl.show()`) are already resolved.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 pl/render.py 开始,阅读现有的 render_images 多通道分支 2A/2B/2C,然后跟踪 render_shapes、render_labels 和 render_points。完成的标准是支持将 2–3 个连续列作为一个轴上的每通道颜色并进行加法混合,同时定义所列出的 palette 长度、混合类型、NaN、归一化和 groups 行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
data-visualization
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。