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

had*_*i k 4 python matplotlib jupyter

现在matplotlib的默认后端是 'module://ipykernel.pylab.backend_inline'

我想切换到TkAGG.我编辑了matplotlibrc文件

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

加上

backend : TkAgg

它确实切换了backendpython而不是Jupyter.

现在,每次我开始使用新笔记本时Jupyter,我都必须这样做%matplotlib tk,不是有一个很好的方法来制作TkAGG默认的后端Jupyter吗?

Imp*_*est 7

问题类似于在IPython Notebook中自动运行%matplotlib inline,除了你想要自动使用TK后端而不是内联后端.

所以我的想法是找到你的IPython配置文件.请参阅配置IPython.它应该是

/.ipython/profile_default/ipython_kernel_config.py
Run Code Online (Sandbox Code Playgroud)

如果它尚不存在,请通过创建它> ipython profile create.

在此文件中找到设置c.InteractiveShellApp.matplotlib并将其设置为"tk".它应该看起来像

## Configure matplotlib for interactive use with the default matplotlib backend.
c.InteractiveShellApp.matplotlib = "tk"
Run Code Online (Sandbox Code Playgroud)

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