How to do sc.pl.heatmap for rank genes, and only the top 25 genes from the ranked gene list

Hi,

I did ranked_gene_groups for a cluster and filtered with adj_pval < 0.05 and log2FC >2, I got a long list that when I used sc.pl.heatmap to show the genes, due to too many gene numbers, the gene’s names can’t show up and I only want to do this heatmap for the top 25 genes.

I’m wondering if you have any great ideas.

Thank you in advance!

Here’s the code I used:

sc.pl.heatmap(m1,groupby=‘batch’,var_names=df_ranked_genes_m1[‘2_n’].tolist(),use_raw=True,swap_axes=True,standard_scale=‘var’, cmap=‘coolwarm’)

Stay well!
Yi

you can try (notice the added [:25]):

sc.pl.heatmap(m1,groupby=‘batch’,var_names=df_ranked_genes_m1[‘2_n’].tolist()[:25],use_raw=True,swap_axes=True,standard_scale=‘var’, cmap=‘coolwarm’)