No support for .obsm keys as color source in render functions
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- data-visualization
Research direction
Start in utils.py around _validate_col_for_column_table (lines 2838–2872) and inspect _locate_value plus the render_shapes, render_labels, and render_points color-resolution paths. Use the minimal example to verify an .obsm DataFrame value can be selected without copying it into obs, and add or update coverage for the chosen key syntax and resulting colors.
Written by the indexing model from the issue text.
Description
No support for .obsm keys as color source in render functions
Environment: spatialdata-plot 0.3.4.dev (main, commit 5cfedc7), Python 3.13
Problem
render_shapes, render_labels, and render_points resolve color= from table.obs columns and table.var_names (gene expression), but they do not check table.obsm. Any per-cell metric stored in .obsm — spatial QC scores, embedding coordinates, tiling statistics, cell neighborhood features — cannot be used for coloring.
Users must work around this by manually copying the .obsm column into .obs, which pollutes the AnnData object and requires extra bookkeeping.
This is tracked in GitHub issue #587.
Minimal reproducible example
import matplotlib; matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np, pandas as pd, geopandas as gpd, anndata as ad
import dask; dask.config.set({"dataframe.query-planning": False})
from shapely.geometry import box
import spatialdata as sd
from spatialdata.models import ShapesModel, TableModel
import spatialdata_plot
shapes = ShapesModel.parse(gpd.GeoDataFrame(
{"geometry": [box(i, 0, i+1, 1) for i in range(3)], "radius": [0.5]*3},
geometry="geometry"
))
obs = pd.DataFrame({
"region": pd.Categorical(["s"]*3),
"instance_id": [0, 1, 2],
})
adata = ad.AnnData(X=np.zeros((3, 1)), obs=obs)
# Per-cell QC metrics stored in obsm — cannot currently use for coloring
adata.obsm["spatial_qc"] = pd.DataFrame(
{"n_counts": [100.0, 250.0, 50.0], "density": [0.8, 0.6, 0.9]},
index=adata.obs_names
)
table = TableModel.parse(adata, region="s", region_key="region", instance_key="instance_id")
sdata = sd.SpatialData(shapes={"s": shapes}, tables={"t": table})
fig, ax = plt.subplots()
# Desired: sdata.pl.render_shapes("s", color="spatial_qc:n_counts").pl.show(ax=ax)
# Actual workaround needed:
adata.obs["n_counts"] = adata.obsm["spatial_qc"]["n_counts"].values
sdata.pl.render_shapes("s", color="n_counts").pl.show(ax=ax)
Expected behaviour
A syntax like color="spatial_qc:n_counts" (or equivalent) that lets users specify an obsm key and column directly, without manually copying into obs.
Actual behaviour
KeyError: "Unable to locate color key 'spatial_qc:n_counts' for element 's'."
.obsm is never checked in _validate_col_for_column_table (utils.py:2838–2872).
Feature request
Extend the color key resolution in _validate_col_for_column_table (and/or _locate_value) to support .obsm DataFrames. Possible syntaxes:
color="obsm_key:column"— explicit separatorcolor="column"with fallback to obsm keys whenobslookup fails- A dedicated
obsm_key=parameter
This would unlock a common workflow where spatial QC, embeddings, or multi-modal per-cell metrics are stored in .obsm and need to be visualized spatially.
Triage tier: Tier 3
- Dominant language
- Python
- Stars
- 86
- Forks
- 21
- Avg merge
- 14h 50m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from scverse/spatialdata-plot
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
scverse/spatialdata-plot#775 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
scverse/spatialdata-plot#777 ·
-
`pl.show()` leading to `ValueError` due to mismatch between number of axes and number of panels Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
scverse/spatialdata-plot#749 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
scverse/spatialdata-plot#747 ·
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
scverse/spatialdata-plot#677 ·
All issues in scverse/spatialdata-plot
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100