在Jupyter Ipython中更改Matplotlib的默认后端 [英] Change default backend for matplotlib in Jupyter Ipython
问题描述
现在,matplotlib的默认后端为'module://ipykernel.pylab.backend_inline'
Right now the default backend for matplotlib is 'module://ipykernel.pylab.backend_inline'
我想将其切换为TkAGG
.我在
~/anaconda2/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc/
添加
backend : TkAgg
,它确实为python切换了backend
,但没有在Jupyter
中切换.
and It did switch the backend
for the python but not in Jupyter
.
现在,每次我在Jupyter
中启动新笔记本时,都必须执行%matplotlib tk
,难道没有一种好方法可以将TkAGG
设置为Jupyter
中的默认后端吗?
For now everytime I start a new notebook in Jupyter
, I have to do %matplotlib tk
, isnt there a nice way to make TkAGG
the default backend in Jupyter
?
推荐答案
The question is similar to Automatically run %matplotlib inline in IPython Notebook, except that you want to automatically use TK backend instead of inline backend.
所以这个想法是找到您的IPython配置文件.请参见配置IPython .应该是
So the idea is to locate you IPython configuration file. See configure IPython. It should be
/.ipython/profile_default/ipython_kernel_config.py
如果尚不存在,请通过> ipython profile create
创建.
If it doesn't yet exist, create it via > ipython profile create
.
在此文件中找到设置c.InteractiveShellApp.matplotlib
并将其设置为"tk"
.然后看起来应该是
Inside this file locate the setting c.InteractiveShellApp.matplotlib
and set it to "tk"
. It should then look like
## Configure matplotlib for interactive use with the default matplotlib backend.
c.InteractiveShellApp.matplotlib = "tk"
保存文件并重新启动内核.
Save the file and restart the kernel.
这篇关于在Jupyter Ipython中更改Matplotlib的默认后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!