%matplotlib inline doesn't work on iPython and Jupyter console

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

I'm trying out Jupyter console for the first time, but can't get the %matplotlib inline magic to work. Below is a screenshot of an example session:

The plot shows in a separate window after I run Line 6, and Line 7 doesn't do anything.

When I run %matplotlib --list, inline is given as one of the options:

Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt', 'nbagg', 'agg', 'gtk', 'tk', 'ipympl', 'inline'] 

When I try to use another backend, say qt5, it gives an error message because I don't have any Qt installed.

ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5, or PySide package to be installed, but it was not found. 

Running %matplotlib?? reads:

 If you are using the inline matplotlib backend in the IPython Notebook         you can set which figure formats are enabled using the following::              In [1]: from IPython.display import set_matplotlib_formats              In [2]: set_matplotlib_formats('pdf', 'svg')          The default for inline figures sets `bbox_inches` to 'tight'. This can         cause discrepancies between the displayed image and the identical         image created using `savefig`. This behavior can be disabled using the         `%config` magic::              In [3]: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None} 

But I don't know if it's something I can tweak around to solve my issue.

When I try it the magic IPython console, it says inline is an Unknown Backend.

UnknownBackend: No event loop integration for u'inline'. Supported event loops are: qt,  qt4, qt5, gtk, gtk2, gtk3, tk, wx, pyglet, glut, osx 

I've also found this issue on github after some googling but I don't even know if it's relevant to my situation (most of their conversation didn't make sense to me lol).

Lastly, I'm not sure if this issue is related at all, but here it is, just in case: when I try to open Vim in Jupyter via the !vim command, it glitches pretty badly, preventing me from even exiting out of Jupyter itself without closing the terminal altogther. Vim works perfectly fine when called inside IPython console, however.

I'm using matplotlib 2.0.0.

If anyone could help me figure this out, that'd be great! Thank you!

回答1:

You’re running a console which is completely text based and incapable of showing images. Therefore, although inline is available, it's not producing inline output.

I'm not sure why it doesn't throw an error, though, which it does in my case:

You can use %matplotlib inline in a GUI console, like Jupyter QTConsole

or in a jupyter notebook in the browser



回答2:

If you're running an old version of ipython try %pylab inline instead. See notes in this tutorial



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