Last active
February 27, 2018 08:17
-
-
Save devlights/2f4faf8c34042dc615200057e194d2b3 to your computer and use it in GitHub Desktop.
[python][dataviz] Bokeh のサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| bokeh のサンプルです。 | |
| 基本パターンについて。 | |
| 参考: | |
| https://bokeh.pydata.org/en/latest/docs/user_guide/quickstart.html#userguide-quickstart | |
| """ | |
| import bokeh.plotting as bp | |
| def go(): | |
| # プロットするデータを用意 | |
| x = list(range(1, 5)) | |
| y = list(range(6, 10)) | |
| # 出力ファイル名を設定 | |
| # これにより、 静的なHTMLファイル が生成される | |
| bp.output_file('lines.html') | |
| # プロットするためのオブジェクトを生成する | |
| # オブジェクトは figure 関数から生成できる | |
| p = bp.figure( | |
| title='lines', # タイトル | |
| x_axis_label='X', # X軸のラベル名 | |
| y_axis_label='Y' # Y軸のラベル名 | |
| ) | |
| # 線グラフを追加 | |
| p.line( | |
| x, # X軸のデータ | |
| y, # Y軸のデータ | |
| legend='hoge', # 判例 | |
| line_width=2 # 線の太さ | |
| ) | |
| # 表示 | |
| # output_fileを指定しているので、ファイルに出力するとともに | |
| # ブラウザにも表示される。 | |
| bp.show(p) | |
| if __name__ == '__main__': | |
| go() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| bokeh のサンプルです。 | |
| レンダラーの複数追加について | |
| 参考: | |
| https://bokeh.pydata.org/en/latest/docs/user_guide/quickstart.html#userguide-quickstart | |
| """ | |
| import bokeh.plotting as bp | |
| def go(): | |
| # プロットするデータを用意 | |
| x = [1, 2, 3, 4, 5] | |
| y = [6, 7, 2, 3, 5] | |
| # 出力ファイル名を設定 | |
| # これにより、 静的なHTMLファイル が生成される | |
| bp.output_file('lines.html') | |
| # プロットするためのオブジェクトを生成する | |
| # オブジェクトは figure 関数から生成できる | |
| p = bp.figure( | |
| title='lines', # タイトル | |
| x_axis_label='X', # X軸のラベル名 | |
| y_axis_label='Y' # Y軸のラベル名 | |
| ) | |
| # 線グラフを追加 | |
| p.line( | |
| x, # X軸のデータ | |
| y, # Y軸のデータ | |
| legend='hoge', # 判例 | |
| line_width=2 # 線の太さ | |
| ) | |
| # レンダラーは複数追加することができる | |
| # 追加した分だけ、プロットされる | |
| p.circle( | |
| x, | |
| y, | |
| legend='hoge2', | |
| size=10, | |
| fill_color='white' | |
| ) | |
| p.patch( | |
| x, | |
| y, | |
| legend='hoge3', | |
| fill_alpha=0.2, | |
| fill_color='yellow' | |
| ) | |
| # 表示 | |
| # output_fileを指定しているので、ファイルに出力するとともに | |
| # ブラウザにも表示される。 | |
| bp.show(p) | |
| if __name__ == '__main__': | |
| go() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://bokeh.pydata.org/en/latest/docs/user_guide/quickstart.html#userguide-quickstart の記述より
bokeh.plottingを用いたプロットの作成の基本パターンは以下のようになる。Bokehにどこに出力するのかを教える (今回はoutput_file()を使用した)figure()を呼び出しプロットオブジェクトを生成p.line())show()またはsave()で出力