lilab-bcb / pegasus

A tool for analyzing trascriptomes of millions of single cells.

Home Page:https://pegasus.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to subplot in pegasus?

x1han opened this issue · comments

commented

Hi, in scanpy, I can create subplots by setting axs in subplot like this:

fig, axs = plt.subplots(4, 6, figsize = (30, 25), dpi = 100)
pal = ['gray'] * 22
cluster = adata_trans.obs['PhenoGraph_clusters'].cat.categories.tolist()
idx = 0
for i in range(4):
    for j in range(6):
        if idx < 22:
            pal[idx] = 'red'
            sc.pl.scatter(adata_trans, color='PhenoGraph_clusters', legend_loc = 'none', title = cluster[idx], ax = axs[i, j], show = False, palette = pal, alpha = 1, basis = 'lt_umap')
            pal[idx] = 'gray'
            idx = idx + 1

plt.show()
plt.close()

75a50b25d411010edb097f2061591d2

However, in the Pegasus plotting function, I did not find a parameter similar to axs. I have spent a long time looking for a way to merge the matplotlib.figure.Figure generated by Pegasus into one image, but I failed. I don't know if you have any suggestions, thank you very much.

Hi @x1han .

The code closest to your example above would be

import pegasus as pg
pg.scatter_groups(data, basis='lt_umap', attr='anno_coarse', groupby='anno_coarse', show_full=False, legend_loc=None, palette=','.join(['red']*22))

However, the major issue of scatter_groups function is that it doesn't show background cells. Even if you set show_full=True, it only generates an additional subplot with all points included.

To directly use pg.scatter function for subplots, so far I also tried some answers from Google, but none of them worked. If you set return_fig=True for scatter function, it would return a matplotlib Figure object, but then how to embed it into a subplot is still something I need to figure out.

I agree that our scatter plot function is not as flexible as directly working with matplotlib's Axes. A quick fix for your example above is to allow scatter_groups function show background cells. A systematic fix for scatter is to allow ax parameter to connect with matplotlib's subplots, but that needs more work.

commented

Hi, @yihming ,
Thanks for the reply, actually, I need the subplot method to plot the de_analysis results of each cluster through pg.volcano, and I want to merge these pictures into one big picture.
I am not sure if Pegasus has built-in plotting functions that can achieve this. Thank you for your answer.