scanpy icon indicating copy to clipboard operation
scanpy copied to clipboard

requesting ncols parameter in sc.pl.violin()

Open rpeys opened this issue 3 years ago • 5 comments

It would be nice to have a way to split the violin plots from sc.pl.violin() into a specific number of rows, similar to the ncols parameter in scanpy.pl.umap()

rpeys avatar Dec 20 '20 02:12 rpeys

Any news on this ??

divyanshusrivastava avatar Feb 23 '22 18:02 divyanshusrivastava

Also looking forward to this update

julie-jch avatar Apr 26 '22 19:04 julie-jch

Looking forward to this update or is there any other way to achieve this?

SNOL2 avatar Feb 19 '23 03:02 SNOL2

It seems that the question has not be addressed yet, and still can't find the ncols parameter alike.

SandyChenn avatar Apr 26 '24 14:04 SandyChenn

Pull requests welcome! You can achieve this e.g. like this:

import itertools
import math

import matplotlib.figure

import scanpy as sc


# parameters
ad = sc.datasets.pbmc68k_reduced()
vars = ["n_genes", "percent_mito", "n_counts", "S_score", "G2M_score"]
n_cols = 3

# plotting code
n_rows = math.ceil(len(vars) / n_cols)
fig = matplotlib.figure.Figure()
axs = fig.subplots(n_rows, 1)
for ax, v in zip(axs.flat, itertools.batched(vars, n_cols)):
    sc.pl.violin(ad, v, ax=ax)
fig

flying-sheep avatar Apr 29 '24 11:04 flying-sheep