Mac上的Anaconda:无法将Matplotlib后端设置为Agg [英] Anaconda on Mac: Can't set Matplotlib backend to Agg

查看:208
本文介绍了Mac上的Anaconda:无法将Matplotlib后端设置为Agg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Spyder设置为使用非交互式matplotlib后端,这样就不会弹出图形,但我仍然可以将图形保存到文件中,

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.

但是,看起来Spyder会自动导入matplotlib并在内部将后端设置在某个位置,因此我对matplotlib.use()进行的任何调用都会弹出一个错误消息,提示已调用MPL.

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.

参考显示自动导入PyLab"已禁用.下拉列表中也没有"Agg"后端.

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?

或者最好是:如何再次允许后端的命令行设置? (我希望脚本在MPL导入之前根据某些变量选择是使用交互式后端还是非交互式后端.)

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首选项截图:

Spyder prefs Screenshot:

版本/尝试,在Mac OS 10.13.6上(显示MPL已经导入!):

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

推荐答案

( Spyder维护人员在这里)如

(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.

这篇关于Mac上的Anaconda:无法将Matplotlib后端设置为Agg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆