%matplotlib内联在iPython和Jupyter控制台上不起作用

发布于 2021-01-29 16:07:15

我第一次尝试使用Jupyter控制台,但无法%matplotlib inline正常工作。以下是示例会话的屏幕截图:

该窗口是6号线的结果,而7号线根本没有执行任何操作。
运行第6行后,该图显示在单独的窗口中,而第7行不执行任何操作。

当我运行时%matplotlib --listinline将作为以下选项之一提供:

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}

但是我不知道这是我可以解决的问题。

当我尝试使用神奇的IPython控制台时,它说inline是一个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

经过一番谷歌搜索后,我也在github上发现了这个问题,但我什至不知道这是否与我的情况有关(他们的大多数谈话对我来说都没有道理)。

最后,我不确定这个问题是否完全相关,只是为了以防万一:当我尝试通过该!vim命令在Jupyter中打开Vim时,它的故障非常严重,甚至阻止了我退出Jupyter本身。无需完全关闭终端。但是,当在IPython控制台中调用Vim时,它工作得很好。

我正在使用matplotlib 2.0.0

如果有人可以帮助我解决这个问题,那就太好了!谢谢!

关注者
0
被浏览
148
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

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

    我不确定为什么它不会引发错误,但在我的情况下确实如此:

    在此处输入图片说明

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

    在此处输入图片说明

    或在浏览器的Jupyter笔记本中

    在此处输入图片说明



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看