scverse / scverse/scanpy

Heatmap does not respect Ordered Categorical

Open
#550 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area - Plotting 🌺 Needs info❔
Dominant language
Python
Stars
2.6k
Forks
779
Avg merge
1d 4h
Merged PRs (30d)
27

Description

I am trying to plot a heatmap to visualize genes that peak at different temporal clusters. I am passing the groupby parameter as the original leiden label transformed into an Ordered Categorical. However, the pl.heatmap API displays the clusters in alphabetic order.

My code and the relative results follows:


# Order of the lineage
lin = ('0', '3', '1', '2', '6', '4')
# Genes to plot
top = ['Malat1', 'Ctdnep1', 'Atxn10', 'Fhl2', 'Etf1']

# Reordering leiden labels using Categorical data type
adata.obs['leiden_res0.6'] = adata.obs['leiden_res0.6'].cat.reorder_categories(list(lin), ordered=True)
# Plotting
sc.pl.heatmap(adata, var_names=top, groupby='leiden_res0.6', cmap='viridis')

pt

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 by reproducing the supplied sc.pl.heatmap example with the ordered categorical leiden_res0.6 and inspect the heatmap implementation's groupby handling. Confirm that the plotted cluster order follows the categorical order rather than alphabetical order, then verify the behavior with the relevant heatmap tests if present.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.