小部件和图形未显示在 Jupyter 实验室中(它们显示为文本)

Widget and graph don't show up in Jupyter lab (they show up as text)

我试图使用 %matplotlib 小部件在 Jupiter Lab 中实现交互。但是输出图和小部件只显示为文本。 如何让实际的情节和小部件显示出来?

%matplotlib widget
import matplotlib.pyplot as plt
plt.figure()
x = [1,2,3]
y = [4,5,6]
plt.plot(x,y)

输出:

Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …
[1]:
[<matplotlib.lines.Line2D at 0x114777b38>]

我遇到了完全相同的问题。显然,Jupyter Lab 版本和软件包存在问题,请参阅 here 其他有相同问题的用户所写的内容。

让我能够看到情节的是:

1.) 确保您已按照建议 here 安装了 Jupyter Lab 版本 > 1.0 和 ipywidgets > 7.5。只需输入 jupyter lab 单元格 !jupyter lab --version!conda list ipywidgets 并自行检查。

2.) 使用命令 jupyter lab 从终端打开 Jupyter Lab。我之前使用的是一个为我创建捷径的程序,所以我不必打开终端,但它打开的是旧版本的 Jupyter Lab

我知道这个问题很老了,但是当我遇到完全相同的问题时 google 把我带到这里,我最终弄明白了。

就我而言,我忽略了安装@jupyter-widgets/jupyterlab-manager。通过实验室扩展选项卡添加这个,重建和重新加载为我解决了这个问题。