ipython控制台绘图后端 tkinter_%matplotlib内联在iPython和Jupyter控制台上不起作用

用户在尝试使用Jupyter Console时遇到了%matplotlib inline魔法命令无法正常工作的问题。尽管该选项可用,但图像并未内联显示,而是打开新窗口。尝试切换到其他后端如qt5时,由于缺少Qt库导致错误。同时,尝试在IPython Console中打开Vim也出现了故障。用户已安装matplotlib 2.0.0,寻求解决方案。
摘要由CSDN通过智能技术生成

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!

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值