在Jupyter Ipython中更改Matplotlib的默认后端 [英] Change default backend for matplotlib in Jupyter Ipython

查看:130
本文介绍了在Jupyter Ipython中更改Matplotlib的默认后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,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屋!

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