如何禁用 Jupyter 笔记本 matplotlib 内联绘图?

问题描述 投票:0回答:3

嗯,我知道我可以使用

%matplotlib inline
来绘制内联图。

但是,如何禁用它呢?

有时我只想放大我绘制的图形。我不能在内嵌图形上做到这一点。

python matplotlib ipython jupyter
3个回答
4
投票

%matplotlib auto
应切换到默认后端。


1
投票

使用

%matplotlib notebook
更改为可缩放显示。


0
投票

我还喜欢将 matplotlib 的绘图绘制在它们自己的单独窗口中,这样您就可以通过它们的控件来操作它们。

但是,我遇到了“空白图”出现或图“冻结”的问题,对思考图标没有反应。

发生这种情况时,我总是会解决它,但并不总是以同样的方式。但以下两种方法中的任何一种总是可以帮助我:

方法1 像这样启动一个单元格:

import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
plt.ion()

然后在下一个单元格中输入:

plt.hist([3,8,10])

在大多数情况下,绘图将出现在自己的窗口中。

方法2 然而,有时(不知道为什么),即使在内核重新启动后,这也不起作用。

您可能会看到一个小窗口出现,它不显示绘图,而是保持空白,如果您将鼠标悬停在它上面,您将获得“思考”图标。

在这种情况下,像这样结束你的绘图单元:

plt.pause(1)

这应该显示图中的绘图,并且它们也应该具有响应能力。

祝你好运!

测试于:

Windows 10
jupyter running inside Visual Studio Code 1.83.1
jupyter_client==8.6.0
jupyter_core==5.7.1
jupyterlab_widgets==3.0.10
python 3.10.13
matplotlib 3.8.2
© www.soinside.com 2019 - 2024. All rights reserved.