跳转到主要内容

Matplotlib Jupyter扩展

项目描述

ipympl

Test Status Latest PyPI version Latest conda-forge version Latest npm version Binder Gitter

利用 Jupyter 交互式小部件框架,ipympl 使 matplotlib 在 Jupyter 笔记本和 JupyterLab 中的交互功能成为可能。

此外,图形 canvas 元素是一个适当的 Jupyter 交互式小部件,可以放置在交互式小部件布局中。

使用方法

要启用 ipympl 后端,只需使用 matplotlib Jupyter 魔法

%matplotlib widget

文档

请参阅以下文档:https://matplotlib.net.cn/ipympl/

示例

请参阅示例笔记本了解更多信息!

matplotlib screencast

安装

使用 conda

conda install -c conda-forge ipympl

使用 pip

pip install ipympl

在 JupyterLab 中使用

如果您想在 JupyterLab 中使用 ipympl,我们建议使用 JupyterLab >= 3。

如果您使用 JupyterLab 2,您仍需要手动安装 labextension

conda install -c conda-forge nodejs
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib

安装旧版 JupyterLab 扩展

如果您正在使用 JupyterLab 1 或 2,您将需要根据您安装的 ipympljupyterlab 版本安装正确的 jupyter-matplotlib 版本。例如,如果您安装了 ipympl 0.5.1,则需要安装 jupyter-matplotlib 0.7.0,此版本仅与 JupyterLab 1 兼容。

conda install -c conda-forge ipympl==0.5.1
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib@0.7.0

版本查找表

ipympl jupyter-matplotlib JupyterLab Matplotlib
0.9.3+ 0.11.3+ >=2,<5 3.4.0>=
0.9.0-2 0.11.0-2 >=2,<5 3.4.0>= <3.7
0.8.8 0.10.x >=2,<5 3.3.1>= <3.7
0.8.0-7 0.10.x >=2,<5 3.3.1>=, <3.6
0.7.0 0.9.0 >=2,<5 3.3.1>=
0.6.x 0.8.x >=2,<5 3.3.1>=, <3.4
0.5.8 0.7.4 >=1,<3 3.3.1>=, <3.4
0.5.7 0.7.3 >=1,<3 3.2.*
... ... ...
0.5.3 0.7.2 >=1,<3
0.5.2 0.7.1 >=1,<2
0.5.1 0.7.0 >=1,<2
0.5.0 0.6.0 >=1,<2
0.4.0 0.5.0 >=1,<2
0.3.3 0.4.2 >=1,<2
0.3.2 0.4.1 >=1,<2
0.3.1 0.4.0 >=0<2

对于开发安装(需要 nodejs)

创建一个已安装 nodejs 的开发环境。以下说明使用 mamba,但您也可以使用 conda。

mamba env create --file dev-environment.yml
conda activate ipympl-dev

安装 Python 包

pip install -e .

在开发您的扩展时,您需要手动使用笔记本/实验室前端启用您的扩展。对于实验室,这是通过以下命令完成的

jupyter labextension develop --overwrite .
jlpm build

对于经典笔记本,您需要运行

jupyter nbextension install --py --symlink --sys-prefix --overwrite ipympl
jupyter nbextension enable --py --sys-prefix ipympl

如何查看您的更改

Typescript:

如果您使用 JupyterLab 进行开发,则可以在不同的终端中同时运行 JupyterLab 以监视源目录,并监视扩展源中的更改,并自动重新构建小部件。

# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab

更改后,等待构建完成,然后刷新浏览器,更改应生效。

Python

如果您更改了 Python 代码,则需要重新启动笔记本内核才能使其生效。

支持