Why don't I need “%matplotlib inline” in my jupyter notebook?

﹥>﹥吖頭↗ 提交于 2021-02-18 14:00:53

问题


I am just trying to understand why my jupyter installation does not require me to run '%matplotlib inline' (which, according to everything I've read, I should have to run that to get my plots inline in my jupyter notebook). But the fact is, my matplotlib plots appear inline in my notebook whether I run '%matplotlib inline' or not. I am running an anaconda install of jupyter on ubuntu under WSL, using chrome as the client to my notebook server. jupyter --version 4.4.0 and jupyter-notebook --version 5.7.8

I've checked my ~/.jupyter/jupyter_notebook_config.py file and see nothing in there about matplotlib.

If I run the following in my notbook:

import matplotlib
matplotlib.get_backend()

This is the output:

'module://ipykernel.pylab.backend_inline'

But if I run ipython directly in my WSL ubuntu window, and then run the above I get:

In [1]: import matplotlib
In [2]: matplotlib.get_backend()
Out[2]: 'agg'

Any idea how I can determine why this works this way? Is it perhaps part of the anaconda installation, that the kernal determines when it is running in a notebook and automatically switches the backend to 'backend_inline' ??

Thanks. Just curious why this is working this way for me.


RESPONDING TO COMMENTS:

@darthbith, each of these was done with a fresh restart of the kernel:

%matplotlib inline
import matplotlib
matplotlib.get_backend()
'module://ipykernel.pylab.backend_inline'

above is same as when I don't run %matplotlib inline

now restart kernel and try %matplotlib notebook:

%matplotlib notebook
import matplotlib
matplotlib.get_backend()
'nbAgg'

来源:https://stackoverflow.com/questions/57085287/why-dont-i-need-matplotlib-inline-in-my-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!