运行两次库以在jupyter上创建交互式图

问题描述 投票:2回答:1

每次我想在Jupyter上有一个交互式的情节,我必须运行两次图书馆。这些库就像这样简单:

import matplotlib.pyplot as plt
%matplotlib notebook

我第一次制作情节时,我有一个静态图像(如此处所示)。如果我再次运行库,该图现在是交互式的。你知道为什么吗?

静态图片:enter image description here

互动图片:enter image description here

python matplotlib jupyter
1个回答
1
投票

您需要在导入pyplot之前设置后端。因此,你的命令顺序很重要。在导入%matplotlib ...之前,您需要输入任何pyplot命令:

%matplotlib notebook
import matplotlib.pyplot as plt
© www.soinside.com 2019 - 2024. All rights reserved.