%matplotlib内联不';不要在iPython和Jupyter控制台上工作

%matplotlib内联不';不要在iPython和Jupyter控制台上工作,python,matplotlib,ipython,jupyter,Python,Matplotlib,Ipython,Jupyter,我是第一次试用Jupyter控制台,但无法让%matplotlib内联魔术正常工作。下面是示例会话的屏幕截图: 在我运行第6行之后,绘图显示在一个单独的窗口中,而第7行什么也不做 当我运行%matplotlib--list时,inline作为选项之一提供: Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt', 'nbagg', 'agg', 'gtk', 'tk', 'ipymp

我是第一次试用Jupyter控制台,但无法让
%matplotlib内联
魔术正常工作。下面是示例会话的屏幕截图:

在我运行第6行之后,绘图显示在一个单独的窗口中,而第7行什么也不做

当我运行
%matplotlib--list
时,
inline
作为选项之一提供:

Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt',
'nbagg', 'agg', 'gtk', 'tk', 'ipympl', 'inline']
当我尝试使用另一个后端时,比如说
qt5
,它会给出一条错误消息,因为我没有安装任何Qt

ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5, or PySide
package to be installed, but it was not found.
运行
%matplotlib???
读取:

 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}
但我不知道这是否是我可以解决问题的办法

当我在magic IPython控制台上试用时,它说
内联
是一个
未知的后端

UnknownBackend: No event loop integration for u'inline'. Supported event loops are: qt, 
qt4, qt5, gtk, gtk2, gtk3, tk, wx, pyglet, glut, osx
我在谷歌上搜索了一下也发现了,但我甚至不知道这是否与我的情况有关(他们的大部分对话对我来说没有意义,哈哈)

最后,我不确定这个问题是否相关,但这里是,以防万一:当我试图通过
在Jupyter中打开Vim时!vim
命令,它的故障非常严重,甚至阻止我在不关闭终端altogther的情况下退出Jupyter本身。然而,当在IPython控制台内调用Vim时,它工作得非常好

我使用的是
matplotlib2.0.0


如果有人能帮我解决这个问题,那就太好了!谢谢大家!

您运行的控制台完全基于文本,无法显示图像。因此,尽管
inline
可用,但它不会生成内联输出

不过,我不确定它为什么不会抛出错误,在我的例子中就是这样:

您可以在GUI控制台中使用
%matplotlib inline
,如Jupyter QTConsole

或者在浏览器的jupyter笔记本中


如果您运行的是旧版本的ipython,请尝试
%pylab inline
。请参见
%matplotlib
没有
内联
对我有效(我使用的是osx和IPython 7.0.1)

我第一次尝试时确实遇到了相同的错误,但不知何故还是能够克服它。不过,我不记得我到底做了什么。无论如何,非常感谢你,这是显而易见的,但我不知道为什么我没有意识到。。哈哈。更新:我使用的是IPython 7.6.1,%matplotlib似乎不再适用于我了。就像Brad说的,你不能将内联图像放入控制台。。。但是我相信%matplotlib inline对大多数系统都有影响-如果没有它,您需要plt.show()在外部窗口中显示图形,并且它会阻止控制台的输入,直到您关闭它。使用%matplotlib inline,您不需要plt.show(),并且它不会阻塞控制台。还值得注意的是,您在MacOS上使用%matplotlib osx而不是内联。