首页 > 解决方案 > jupyter lab 中的 Bqplot 返回字符串而不是(交互式)图像

问题描述

今天我一直在尝试安装模块 bqplot 并第一次使用 jupyter lab。

但是,当使用他们网站上显示的基本示例时,我无法获得所需的输出。

我试图执行的代码如下:

import numpy as np
from bqplot import pyplot as plt

plt.figure(1, title='Line Chart')
np.random.seed(0)
n = 200
x = np.linspace(0.0, 10.0, n)
y = np.cumsum(np.random.randn(n))
plt.plot(x, y)
plt.show()

在 jupyter(实验室)单元中运行此代码后,给定的输出为:

VBox(children=(Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig…

而在普通的 jupyter notebook 中,输出显示的是示例图像。

到目前为止,我不知道出了什么问题,希望能提供任何帮助!

谢谢。

标签: python-3.xjupyter-notebookjupyter-labbqplot

解决方案


我遇到了同样的问题,并通过安装bqplotlabextension 和@jupyter-widgets/jupyterlab-manager扩展来解决它:

jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install bqplot

重新启动 jupyter lab 后,将显示小部件。

我猜误解在于 bqplot 的安装说明:它仅将这些步骤称为“实验性 JupyterLab 扩展”,但在 Jupter Lab 中启用 bqplot 的安装步骤却忽略了它们。


推荐阅读