Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

python 3.x - Anaconda on Mac: Can't set Matplotlib backend to Agg

I want to set Spyder to use a non-interactive matplotlib backend, so that plot figures do not pop up but I can still save figures to file, like this hint.

However, it looks like Spyder automatically imports matplotlib and sets the backend internally somewhere, so any call I make to matplotlib.use() pops an error saying that MPL has already been called.

Prefs show that "automatically import PyLab" is disabled. Also there is no 'Agg' backend in the dropdown list.

How do I use a non-interactive backend?

Or preferably: how can I allow command-line setting of the backend again? (I would like my script to choose whether to use the interactive/non-interactive backends depending on some variables, before MPL import.)

Spyder prefs Screenshot: enter image description here

Versions/attempt, on Mac OS 10.13.6 (shows MPL already imported!):

Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 11:07:29)

IPython 6.5.0 -- An enhanced Interactive Python.

>> matplotlib
Using matplotlib backend: Qt5Agg
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

(Spyder maintainer here) As mentioned by @ImportanceOfBeingErnest in his comment above, you simply need to turn off the option called Activate Support in the screenshot you posted to be able to set by yourself the Matplotlib backend you want to use in your code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...