jupyterlab互动p

2024-05-23 22:51:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Jupyter笔记本上的Jupyterlab。在笔记本中,我经常使用:

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

用于交互式绘图。现在给了我(在朱庇特实验室):

JavaScript output is disabled in JupyterLab

我也试过这个魔术(安装了jupyter-matplotlib):

%matplotlib ipympl

但这又回来了:

FigureCanvasNbAgg()

内联绘图:

%matplotlib inline

工作很好,但我想要互动的情节。


Tags: import绘图outputplotmatplotlibas笔记本jupyter
3条回答

根据Georgy's suggestion,这是由于没有安装Node.js造成的。

完成步骤

  1. 安装nodejs,例如conda install nodejs
  2. 安装ipympl,例如pip install ipympl
  3. [可选,但推荐;更新JupyterLab,例如
    pip install --upgrade jupyterlab.]
  4. [可选,但推荐;对于本地用户安装,请运行:
    export JUPYTERLAB_DIR="$HOME/.local/share/jupyter/lab"。]
  5. 安装扩展:

    jupyter labextension install @jupyter-widgets/jupyterlab-manager
    jupyter labextension install jupyter-matplotlib
    
  6. 启用小部件:jupyter nbextension enable --py widgetsnbextension

  7. 重新启动JupyterLab。
  8. %matplotlib widget装饰。

不建议这样做,但要盲目地让小部件扩展在Anaconda中工作,可以在终端窗口中运行以下命令:

conda install -y nodejs
pip install ipympl
pip install --upgrade jupyterlab
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install jupyter-matplotlib
jupyter nbextension enable --py widgetsnbextension

要启用jupyter matplotlib后端,请使用matplotlib jupyter魔术:

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

这里有更多信息jupyter-matplotlib on GitHub

Screenshot Jupyter Lab

相关问题 更多 >