安装#

在大多数情况下,您只需执行以下操作:

pip install ipympl

或者您也可以使用 mamba/conda

mamba install -c conda-forge ipympl

然后重启 Jupyter。

Jupyterlab < 3#

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

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

Google Colab#

若要在 Colab 中使用 ipympl,请运行以下代码行:

from google.colab import output
output.enable_custom_widget_manager()

混合前端和后端版本#

ipympl 提供了前端(用 JavaScript 编写,负责显示绘图和处理交互事件)和后端(用 Python 编写,负责渲染绘图并与用户代码交互)。这两个部分需要相互通信才能正常工作。在最常见的情况下,如果您的前端和后端来自同一个 Python 环境,那么安装 ipympl 应该会为您提供兼容的版本。

然而,在某些情况下,您可能在前端和后端拥有不同版本的 ipympl。在这种情况下,您需要确保前端和后端版本兼容。有关详细信息和初始兼容性表格,请参阅此 GitHub 问题上的讨论。

兼容性表格#

并非所有版本的 ipympl 都与不同版本的 Jupyterlab 或所有版本的 Matplotlib 兼容。下表提供了哪些版本兼容的参考。

ipympl

jupyter-matplotlib

JupyterLab

Matplotlib

0.9.5-7

0.11.5-7

>=2,<5

>=3.5.0

0.9.3-4

0.11.3-4

>=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

3 或 2

3.3.1>= <3.7

0.8.0-7

0.10.x

3 或 2

3.3.1>=, <3.6

0.7.0

0.9.0

3 或 2

3.3.1>=

0.6.x

0.8.x

3 或 2

3.3.1>=, <3.4

0.5.8

0.7.4

1 或 2

3.3.1>=, <3.4

0.5.7

0.7.3

1 或 2

3.2.*

0.5.3

0.7.2

1 或 2

0.5.2

0.7.1

1

0.5.1

0.7.0

1

0.5.0

0.6.0

1

0.4.0

0.5.0

1

0.3.3

0.4.2

1

0.3.2

0.4.1

1

0.3.1

0.4.0

0 或 1