安裝#

在大多數情況下,您只需要執行以下命令即可

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 issue 的討論。

相容性表格#

並非所有版本的 ipympl 都與不同版本的 Jupyterlab 或所有版本的 Matplotlib 相容。下表提供了哪些版本相容的參考。

ipympl

jupyter-matplotlib

JupyterLab

Matplotlib

0.9.5

0.11.5

>=2,<5

>=3.5.0

0.9.4

0.11.4

>=2,<5

3.4.0>=

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

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