Match plot colors (squidpy)¶
Color the Landmarks map from Squidpy niche labels and reuse the same hex colors in Matplotlib or Scanpy plots.
Goal¶
Run Squidpy neighborhood niches on a selection, assign w.color to the niche column Squidpy writes, and read colors back with w.category_colors.
Steps¶
- Install optional analysis packages:
- Open the ileum slice and draw a region to analyze (or use the whole tissue):
import milume as ml
import squidpy as sq
adata = ml.ds.ileum_merfish_xu2026()
w = ml.peek(adata, color="cell_type")
w # draw a selection in the browser, then continue
- Build a boolean mask aligned to
adata.obs_namesfor the selection you want:
- Run Squidpy niches on that mask (neighbors + spatial graph first):
sc.pp.neighbors(adata)
sq.gr.spatial_neighbors_knn(adata, n_neighs=6)
sq.gr.calculate_niche(
adata,
flavor="neighborhood",
groups="cell_type",
n_neighbors=6,
resolutions=0.5,
mask=mask,
)
niche_col = "nhood_niche_res=0.5"
- Colour the map from the new column:
- Reuse the map palette elsewhere:
Result¶
Landmarks points and downstream plots share the same label-to-color mapping as the map.
For a prepared studio walkthrough (fixed selection and export state), use the Squidpy niche color recipe or the live molab notebook. The recipe export pipeline is unchanged; this page is the task-only steps.
Squidpy and Scanpy parameters stay in their own docs; milume traitlets are in the LandmarksWidget API.