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

Document that the matplotlib backend will be set to Agg #153

Closed
anntzer opened this issue Oct 16, 2016 · 4 comments · Fixed by #157
Closed

Document that the matplotlib backend will be set to Agg #153

anntzer opened this issue Oct 16, 2016 · 4 comments · Fixed by #157

Comments

@anntzer
Copy link
Contributor

anntzer commented Oct 16, 2016

While trying to use sphinx-gallery to document my mplcursors (https://mplcursors.readthedocs.io/en/stable/) package, I got the following (well-known) warning:

UserWarning:  This call to matplotlib.use() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

Turns out that in my conf.py, I already import mplcursors/__init__.py (in order to get the version set by versioneer out of it), and that this triggers an import of matplotlib.pyplot (which I can actually get rid of, but that's irrelevant here). A simple solution was simply to set the backend to Agg before importing mplcursors.

Documenting this point could perhaps save some head-scratching for others too.

@lesteve
Copy link
Member

lesteve commented Oct 18, 2016

Makes sense. I am wondering whether it would not be possible to raise an error inside sphinx-gallery if the matplotlib backend has already been set to something else that Agg.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 18, 2016

Given that switching backends is rather poorly supported by matplotlib, that probably makes sense.

@Titan-C
Copy link
Member

Titan-C commented Oct 26, 2016

Makes sense. I am wondering whether it would not be possible to raise an error inside sphinx-gallery if the matplotlib backend has already been set to something else that Agg.

I prepared PR #157. It will issue a warning instead of raising an error.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 26, 2016

btw, matplotlib/matplotlib#7303 was merged into matplotlib recently, so that may or may not be enough by itself.

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

Successfully merging a pull request may close this issue.

3 participants