Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not return matplotlib.Axes in python script #259

Open
AfterDream opened this issue Apr 8, 2024 · 1 comment
Open

Could not return matplotlib.Axes in python script #259

AfterDream opened this issue Apr 8, 2024 · 1 comment

Comments

@AfterDream
Copy link

Setup

I am reporting a problem with gseapy == 1.1.2,
Python == 3.8.19, and
operatingsystem == Ubuntu 20

My code as follows, the goal is to have gseapy complete the enrichment of each cluster in the for loop and save the resulting image to the local, I tested the feasibility in jupyter, but when executed in a standalone script, only a blank canvas was generated,unable to obtain matplotlib.Axes object, ignored the ofname parameter according to the document

import gseapy as gp
from gseapy import barplot, dotplot

import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('Agg')

for cluster in adata.obs['cluster'].value_counts().index.values:
    glist = sc.get.rank_genes_groups_df(adata, group=cluster,key ='wilcoxon', log2fc_min=1, pval_cutoff=0.05)['names'].squeeze().str.strip().tolist()
    print(cluster + "------------"+ str(len(glist)))
    if len(glist) > 10:
        go_enrich_res = gp.enrichr(gene_list=glist,
                            organism=species,
                            gene_sets=['GO_Biological_Process_2023','GO_Cellular_Component_2023','GO_Molecular_Function_2023'],  #
                            no_plot = True,
                            cutoff = 0.05)
        go_df = go_enrich_res.results
        if len( go_df[go_df["Adjusted P-value"] < 0.05] ) >0:
            ax = gp.barplot(go_df, figsize=(8,12),
                            group ='Gene_set',
                            column="Adjusted P-value",
                            title ="GO",
                            top_term = 10,
                            no_plot= True,
                            show=False,
                            color = ['b','r','y'])
            plt.savefig(fig_outdir+'05_'+cluster+'_marker_genes_GO_enrichment.png', bbox_inches="tight")
            plt.close() 
@zqfang
Copy link
Owner

zqfang commented Apr 9, 2024

You can set ofname to save your file in barplot

By default, plt.savefig will save figure in interactively mode. e.g. jupyter

In script mode, gseapy turns off the matplotlib's interactive GUI to avoid opening too many windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants