在Jupyter Ipython中更改matplotlib的默认后端

6

目前,matplotlib的默认后端是'module://ipykernel.pylab.backend_inline'

我想将其切换为TkAGG。我编辑了matplotlibrc文件:

~/anaconda2/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc/

加入了:

backend : TkAgg

这确实在python中切换了backend,但在Jupyter中没有变化。

目前每次在Jupyter中启动新的notebook时,都需要执行%matplotlib tk命令。有没有一种好的方法来使TkAGG成为Jupyter的默认后端?

1个回答

8

这个问题类似于Automatically run %matplotlib inline in IPython Notebook,只不过你想要自动使用TK后端而不是inline后端。

因此,想法是定位您的IPython配置文件。请参见配置IPython。它应该在

/.ipython/profile_default/ipython_kernel_config.py

如果还没有ipython配置文件,请通过命令> ipython profile create创建一个。
在该文件中,找到设置项c.InteractiveShellApp.matplotlib并将其设置为"tk"。设置完成后,该项应当如下所示:
## Configure matplotlib for interactive use with the default matplotlib backend.
c.InteractiveShellApp.matplotlib = "tk"

保存文件并重新启动内核。


1
这确实有帮助。谢谢。我看过类似的问题,但不知何故错过了这个。 - jkhadka

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接