Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

JupyterLabでPlotlyのグラフを表示する

公開日 2024-12-12

JupyterLab上にPlotlyのグラフを表示する方法を解説します。

ライブラリのインストール

ライブラリをインストールする前に、必要に応じて仮想環境を構築します。 Windowsでvenvを使用する場合、PowerShellで以下のコマンドを実行します。

python -m venv venv

次に、以下のコマンドを実行して仮想環境の中に入ります。

.\venv\Scripts\Activate.ps1

必要なライブラリ (JupyterLabとPlotly, Pandas) をインストールします。

pip install jupyterlab plotly pandas

JupyterLabの起動

ライブラリのインストール完了後、以下のコマンドをPowerShellで実行し、JupyterLabを起動します。

jupyter-lab.exe

ウェブブラウザにJupyterLabのページが表示されます。

Plotlyグラフの表示

JupyterLabでPlotlyのグラフが表示されることを確認します。 セルで以下のコードを実行します。

import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.update_layout(height=500)
fig.show()
Loading...

このページはQiita Python アドベントカレンダー 2024 12日目の記事です。