scverse / scverse/scanpy

scanpy.pl.stacked_violin - remove "marker label" whitespace if var_names is a list of genes

Open
#3,320 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Please make sure these conditions are met
  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.
What happened?

Basically I am creating a stacked violin plot that uses a list of marker genes for the "var_names" argument. But whenever I create the plot, it has extra whitespace at the top of the plot where the marker gene labels should go. This is very evident when you add a figure title, which gets place above the padding whitespace. I have not really found a way around this, and am currently looking through the scanpy internal code to see if there is some padding setting that I can undo. If there is a workaround to this or some option that I am missing I would like to know.

Thanks!

Minimal code sample
# I have an AnnData object that has undergone the Seurat analysis. I named the Leiden clustering output "spatial_clusters" since I was testing a spatial dataset read in via spatialdata then converted to AnnData with "spatialdata_io.experimental.to_legacy_anndata"

marker_genes = ["Pou4f3", "Calb2", "Pvalb", "Smpx", "Mlf1", "Sox2"]  # 5 random Cochlear HCs P7 + Sox2

sc.pl.stacked_violin(adata, marker_genes, title="Marker gene expression per cluster", groupby="spatial_clusters", cmap="YlOrRd", show=False, return_fig=True)

### COMPARISON TO MARKER GENES WITH LABELS
marker_genes = {"IHC": ["Pou4f3", "Calb2", "Pvalb", "Smpx", "Mlf1"], "Random": ["Sox2"]}

sc.pl.stacked_violin(adata, marker_genes, title="Marker gene expression per cluster", groupby="spatial_clusters", cmap="YlOrRd", show=False, return_fig=True)

Error output

Will post in the next comment on this thread. Seems I cannot drag-n-drop images into this block.

Versions

I am including relevant package versions. Can provide more if needed

Python 3.12.7

anndata==0.10.6
matplotlib==3.9.0
pandas==2.2.1
scanpy-1.10.3

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 at the sc.pl.stacked_violin entry point and reproduce the two examples with var_names as a list and as a labeled dictionary. Compare the resulting layout, especially the top whitespace and title placement; done means the list-of-genes case no longer reserves space for marker labels while the labeled case still works.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.