[ipywidgets] 19. Jupyter labでipywidgetsを動かす

ipywidgets

はじめに

jupyter labでipywidgetsを使おうとして、冒頭に%matplotlib notebookと入れても動作しません。
ここでは、jupyter labでipywidgetsを使う方法について説明します。

解説

ipywidgetsのインストール

conda install -c conda-forge ipywidgets 

condaを使ってipywidgetsをインストールします。

jupyter-matplotlibのインストール

conda install -c conda-forge ipympl

jupyter notebookまたはlabでインタラクティブな図を表示できるjupyter-matplotlibをインストールします。

nodejsのインストール

conda install -c conda-forge nodejs

jupyter labの拡張機能はnodejsで動いているのでインストールします。

拡張機能のインストール

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

jupyter labの拡張機能をインストールします。インストール後にbuildすることで使えるようになります。

ipywidgetsをjupyterlabで使う

%matplotlib widget

実際にjupyter labでipywidgetsを使うには、%matplotlib inlneや%matplotlib notebookの代わりに%matplotlib widgetとコードの冒頭に記述します。

参考

Installation — Jupyter Widgets 8.1.2 documentation
GitHub - matplotlib/ipympl: Matplotlib Jupyter Integration
Matplotlib Jupyter Integration. Contribute to matplotlib/ipympl development by creating an account on GitHub.

コメント