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

Rank_genes_groups -> does not return Axes #3205

Open
3 tasks done
dansteiert opened this issue Aug 12, 2024 · 4 comments · May be fixed by #3428
Open
3 tasks done

Rank_genes_groups -> does not return Axes #3205

dansteiert opened this issue Aug 12, 2024 · 4 comments · May be fixed by #3428

Comments

@dansteiert
Copy link

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?

Function Rank_genes_groups() does not return a figure -> returns None type
Cannot get Figure via plt.gcf(), plt.gca().

Potential Fix:
https://github.com/scverse/scanpy/blob/main/src/scanpy/plotting/_tools/__init__.py
Line 485: cann be extended to the following as in other functions below:

    savefig_or_show(f"{key}_", show=show, save=save)
    show = settings.autoshow if show is None else show
    if show:
        return None
    return ax

Minimal code sample

fig = sc.pl.rank_genes_groups(adata, show=False)
type(fig)
#NoneType
plt.gca() -> empty axes
plt.gcf() -> empty figure

Error output

No response

Versions

-----
anndata     0.10.8
scanpy      1.10.2
-----
@dansteiert dansteiert added Bug 🐛 Triage 🩺 This issue needs to be triaged by a maintainer labels Aug 12, 2024
@flying-sheep flying-sheep added Enhancement ✨ Area - Plotting 🌺 and removed Bug 🐛 Triage 🩺 This issue needs to be triaged by a maintainer labels Oct 25, 2024
@flying-sheep
Copy link
Member

The docs don’t say it does, so this would be an enhancement, not a bug fix.

it’s not high priority, since it’s easy to just do ax = plt.subplot(); sc.pl.rank_genes_groups(adata, ax=ax)

contributions are welcome!

@dansteiert
Copy link
Author

This might be true the expected behaviour is not mentioned here.
Then as you pointed out it is more of an enhancement, which would be to make it match other plotting functions behaviour ;)

@TKMarkCheng
Copy link

TKMarkCheng commented Jan 6, 2025

Hi, I am currently also having the same issue - even plotting on ax suggested by @flying-sheep doesn't help with the issue for rank_genes_group but all the embedding plotting function works.

it is an unexpected behaviour given the advanced plotting docs alludes to that it will work with multiple plot types.

Maybe it's something fundamental with how savefig_or_show() is called?

In tsne/umap/scatterplots in general which goes through embedding(), whilst
other functions in src/scanpy/plotting/_tools/__init__.py e.g. rank_genes_groups() directly calls savefig_or_show() at the end

@flying-sheep
Copy link
Member

I think I looked wrong: it does have an ax parameter which is defunct.

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

Successfully merging a pull request may close this issue.

3 participants