scverse / scverse/napari-spatialdata

Colors categorical column in table annotated by a labels layer not correct in napari-spatialdata

Open
#328 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
90
Forks
25
Avg merge
22m
Merged PRs (30d)
1

Description

I provide some code to reproduce the issue:

import numpy as np
import scanpy as sc

from spatialdata.datasets import blobs

import matplotlib
import matplotlib.pyplot as plt
import spatialdata_plot

np.random.seed(10)

sdata=blobs(length=1000, n_channels=3)

sc.pp.pca(sdata[ "table" ], copy=False,)

sc.pp.neighbors(sdata["table" ], copy=False,)
sc.tl.umap(sdata["table"], copy=False,)

sdata[ "table" ].obs['new_category'] = np.random.randint(0, 15, size=len( sdata[ "table" ].obs ))
sdata[ "table" ].obs['new_category']=sdata[ "table" ].obs['new_category'].astype( "category" )

sc.pl.umap(sdata.tables["table"], color=["new_category"], show=True)

plt.figure(figsize=(5, 5))
ax = plt.gca()

column = "new_category"

adata = sdata[ "table" ]

cmap = matplotlib.colors.LinearSegmentedColormap.from_list(
                    "new_map",
                    adata.uns[column + "_colors"],
                    N=len(adata.uns[column + "_colors"]),
                )

sdata.pl.render_labels("blobs_labels", color=column,cmap =cmap, method="datashader", fill_alpha=1).pl.show(
    coordinate_systems="global", ax=ax
)

Gives me the umap:

Image

spatialdata-plot correctly plots the column "new_category":

Image

But when I do


from napari_spatialdata import Interactive

Interactive( sdata )

I get:

Image

The large cell in the bottom is visualized as having "new_category" '6' with napari-spatialdata, while spatialdata_plot, correctly plots it as having "new_category" '7'.

I am using the latest version of napari-spatialdata ( 0.5.3 ), and I am using macOS (I do not know if this is relevant, but given https://github.com/scverse/napari-spatialdata/issues/273, it may be).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided reproduction and the Interactive(sdata) entry point; compare its categorical label-color mapping with the preceding spatialdata_plot render_labels call. Trace how new_category values are assigned to labels, and verify completion by making the large cell display category 7 rather than 6, matching spatialdata_plot.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.