はじめに
jupyter notebookの対話的にパラメータを調整できる機能(ipywidgets ColorPicker)で、図のマーカーの色をインタラクティブに変化させる方法について説明する。
コード

解説
モジュールのインポートなど
データの生成
np.cumsum()は累積和となる。
図の表示
ipywidgetsの設定
ColorPickerで、concise=Falseにより簡易表示ではない状態にする。description=’marker color:’はカラーピッカー前に表示される説明のためのラベルとなる。value=’green’で初期値を緑とした。
p.set_color(color_picker)でマーカーの色をカラーピッカーで選択した色へと変更する。
ColorPickerで色を変化させたときの図の変化


直接色名を入力することでもマーカーの色を変えることができる。
コードをダウンロード(.pyファイル) コードをダウンロード(.ipynbファイル)参考
Using Interact — Jupyter Widgets 8.1.5 documentation
Widget List — Jupyter Widgets 8.1.5 documentation
コメント