scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.94k stars 604 forks source link

Split violin plot #1448

Closed brianpenghe closed 4 years ago

brianpenghe commented 4 years ago

Hello, Currently only scanpy.pl.rank_genes_groups_violin can give us a split violin plot. But can we request a feature to allow us to do a split-violinplot of our own gene lists?

image

Thanks

fidelram commented 4 years ago

Can you elaborate? You can use sc.pl.violin independently.

brianpenghe commented 4 years ago

Can you elaborate? You can use sc.pl.violin independently.

OK I just updated my question and attached a sample image. What I want to do is split-violinplot.

fidelram commented 4 years ago

Thanks for the update. Now is clear.

We do not offer that possibility as most of those functions are based on seaborn, thus, simply passing the relevant data to seaborn will get you the image that you want.

Nevertheless, I would like to take a look. How do you think this should work. Just add a variable to show the genes that you would like to see. Or you mean a more generic function just to make split plots between any two categories for the genes that you want to see?

brianpenghe commented 4 years ago

Thanks for the update. Now is clear.

We do not offer that possibility as most of those functions are based on seaborn, thus, simply passing the relevant data to seaborn will get you the image that you want.

Nevertheless, I would like to take a look. How do you think this should work. Just add a variable to show the genes that you would like to see. Or you mean a more generic function just to make split plots between any two categories for the genes that you want to see?

Thanks for your attention. Yes it would be nice if I could compare two .obs categories with regard to expression distributions of a list of genes I supply.

Thanks!

fidelram commented 4 years ago

This is a way to do it btw:

adata = sc.datasets.pbmc68k_reduced()
adata = adata[adata.obs.louvain.isin(['0','1'])].copy()
df = sc.get.obs_df(adata, ['PTPN7', 'SMAP2', 'PPDPF', 'louvain'])
df = df.set_index('louvain').stack().reset_index()
df.columns = ['louvain', 'gene', 'value']
import seaborn as sns
sns.violinplot(data=df, x='gene', y='value', hue="louvain",
                split=True, inner="quart", linewidth=1)           

image

brianpenghe commented 4 years ago

Thank you very much!

howtofindme commented 1 year ago

This is a way to do it btw:

adata = sc.datasets.pbmc68k_reduced()
adata = adata[adata.obs.louvain.isin(['0','1'])].copy()
df = sc.get.obs_df(adata, ['PTPN7', 'SMAP2', 'PPDPF', 'louvain'])
df = df.set_index('louvain').stack().reset_index()
df.columns = ['louvain', 'gene', 'value']
import seaborn as sns
sns.violinplot(data=df, x='gene', y='value', hue="louvain",
                split=True, inner="quart", linewidth=1)           

image

Thanks for the suggestion! I am new to pthon. In your samples, you have '0' and '1' conditions in 'louvain'. But what if I have three conditions, How can I split the violin?

Best, Young