Skip to content

Instantly share code, notes, and snippets.

@wakita
Last active March 30, 2022 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wakita/87b39e8d463f3d279c21c3e15a1cd9c7 to your computer and use it in GitHub Desktop.
Save wakita/87b39e8d463f3d279c21c3e15a1cd9c7 to your computer and use it in GitHub Desktop.
Jupyter Lab + IJulia + PlotlyJS の環境構築

Jupyter Lab + IJulia + PlotlyJS の環境構築

いくつかの Python 基盤を利用した Jupyter の上で IJulia を介して PlotlyJS が動作することを Apple M1 の ARM 環境で検証。

詳しい解説はQiita 記事

環境構築

  1. 指定したバージョンの Python に対応した venv 仮想環境を作成し、そこに Jupyter Lab をインストール
  2. Jupyter Lab を PlotlyJS に対応させるための拡張機能をインストール
  3. Jupyter の在処を IJulia に伝えるための環境変数の設定
  4. Julia の起動(Julia のプロジェクトとして仮想環境のディレクトリを指定しつつ)

実行

  1. Julia に IJulia と PlotlyJS をインストール、初期化。Pkg.build(pkg) は不要かもしれない。
  2. Jupyter Lab の起動
#!/bin/sh
#=
# Python-side installation
case "$1" in
apple)
venv=$1
python=/usr/bin/python3 ;;
homebrew)
venv=$1
python=/opt/homebrew/bin/python3 ;;
*) exit 1
esac
if [ ! -f $venv ]; then
$python -m venv $venv
$venv/bin/pip install --upgrade pip jupyterlab
$venv/bin/jupyter labextension install jupyterlab-plotly
fi
# Configuration: letting IJulia know the jupyter path
export JUPYTER=/tmp/t/$venv/bin/jupyter
# Starting Julia
exec julia --project=$venv $0 $@
=#
# Julia-side installation
using Pkg
for pkg in ["IJulia", "PlotlyJS"]
Pkg.add(pkg)
Pkg.build(pkg)
end
using IJulia
jupyterlab()
# テストには以下のコードをお使い下さい。
using PlotlyJS
t1 = scatter(;x=[1, 2, 3, 4, 5],
y=[1, 6, 3, 6, 1],
mode="markers+text",
name="Team A",
text=["A-1", "A-2", "A-3", "A-4", "A-5"],
textposition="top center",
textfont_family="Raleway, sans-serif",
marker_size=12)
plot(t1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment