LoginSignup
77
81

More than 5 years have passed since last update.

Jupyter Notebookを動的に使ってみる

Last updated at Posted at 2016-03-01

現在の環境

RISE

  • 以前からlive_revealを使って動的なHTMLが生成できたが、最近はRISEというプロジェクトが良い様子
  • ipython 3.x+live_revealの時はなぜか環境構築できなかったが、今回はさくっと入った
git clone https://github.com/damianavila/RISE
cd RISE
python setup.py install
  • これでlocalhostのjupyterにスライドショーボタンが追加される
  • 動的なHTMLでプレゼンできて、中のコードまで書き換えられる
  • とういうところまで書いて、すでに素晴らしいQiitaの記事があったのに気づいた。

pivottablejs

参考URL

conda install pivottablejs
  • pandasのグラフ描画を拡張して、動的にテーブルから散布図に切り替えたり、散布図の軸などを変えることができる。 pvjs.png

ipywidgets.interact

  • こちらも素晴らしいQiitaの記事がある。
  • Jupyter 4.xではIPython.html.widgetsは非推奨になりipywidgetsになった。
  • インストール conda install ipywidgets

Screenshot 2016-03-01 at 13.20.30.png

interactに関数とパラメータを渡すと、パラメータを変化させるwidgetが生成します。
Screenshot 2016-03-01 at 13.22.01.png

interactを関数のデコレータとして使うこともできて、
こちらの方法もかなりスマートです。

Screenshot 2016-03-01 at 13.26.30.png

bokeh

  • まだバージョンアップが頻繁でAPIが安定していないが、bokehというヴィジュアライズの拡大縮小などができるライブラリがある。
  • 参考
  • interectにパラメータの指定をさせて、bokehで描画するとspotfireとかtableauとかを使っている気分になる。
conda install bokeh

使用例

from sklearn.datasets import load_breast_cancer
import pandas as pd
cancer=load_breast_cancer()
data=pd.DataFrame(cancer.data,columns=cancer.feature_names)
data["target"]=[cancer.target_names[i] for i in cancer.target]
def interactivebokeh(x_axis,y_axis):
    fig=bplt.figure(plot_width=640, plot_height=320)
    fig.circle(
                data[data.target=="malignant"][x_axis],
                data[data.target=="malignant"][y_axis],
                line_color="red",fill_color="red"
                )
    fig.square(
                data[data.target=="benign"][x_axis],
                data[data.target=="benign"][y_axis],
                line_color="blue",fill_color="blue"
                )
    bplt.show(fig)

Screenshot 2016-03-01 at 14.02.40.png

77
81
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
77
81