利用 Jupyter 交互式小部件框架,jupyter-matplotlib 可以在 Jupyter notebook 和 Jupyterlab 中实现 matplotlib 的交互功能。
此外,canvas 是一个合适的 Jupyter 交互式小部件,可以定位在交互部件的 Layout 上。
Github 链接:
https://github.com/matplotlib/jupyter-matplotlib
用法:
要启用 jupyter-matplotlib 后端,只需使用 matplotlib:
%matplotlib widget
示例:
安装:
使用 conda 安装 ipympl:
condainstall-c conda-forge ipympl
#Ifusingthe Notebook
condainstall-c conda-forge widgetsnbextension
#IfusingJupyterLab
condainstallnodejs
jupyter labextensioninstall@jupyter-widgets/jupyterlab-manager
使用pip安装ipympl:
pipinstallipympl
#IfusingJupyterLab
#Installnodejs: https://nodejs.org/en/download/
jupyter labextensioninstall@jupyter-widgets/jupyterlab-manager
对于开发安装(需要节点)
git clone https://github.com/matplotlib/jupyter-matplotlib.git
cd jupyter-matplotlib
pipinstall-e .
jupyter nbextensioninstall--py --symlink --sys-prefix ipympl
jupyter nbextensionenable--py --sys-prefix ipympl
jupyter labextensioninstall@jupyter-widgets/jupyterlab-manager--no-build
jupyter labextensionlink./js
cd js && npm run watch
# Launch jupyterlabas`jupyter lab --watch`inanother terminal
领取专属 10元无门槛券
私享最新 技术干货