Bokeh: Quick Start

From OnnoWiki
Jump to navigation Jump to search

Sumber: http://bokeh.pydata.org/en/latest/docs/quickstart.html


Instalasi Anaconda

Klik Cara Instalasi Anacoda


Instalasi

Jika kita menggunakan Anaconda, kita dapat menggunakan

easy_install -U pip
conda install bokeh

Ini akan menginstalasi secara lengkap, tanpa pusing.

Jika kita cukup Percaya Diri (PD) bahwa kita mempunyai semua dependensi yang bidiagonal seperti NumPy, Pandas, dan Redis, maka kita dapat menggunakan,

easy_install -U pip
pip install bokeh

Instalasi Web Server

sudo apt-get install apache2 php5 php5-xmlrpc php5-mysql \
php5-gd php5-cli php5-curl mysql-client mysql-server

Contoh Line Chart

Lakukan

cd /var/www/html

Buat file

vi /var/www/html/lines.py

Isi dengan

from bokeh.plotting import figure, output_file, show

# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

# output to static HTML file
output_file("lines.html", title="line plot example")

# create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')

# add a line renderer with legend and line thickness
p.line(x, y, legend="Temp.", line_width=2)

# show the results
# show(p)

Jalankan

cd /var/www/html
python /var/www/html/lines.py

Akses menggunakan browser

http://ip-server/lines.html


Langkah untuk membuat plot menggunakan bokeh.plotting interface adalah:


  • Siapkan data (disini menggunakan python lists).
  • Perintahkan Bokeh untuk membuat output (disini menggunakan output_file(), dengan nama file "lines.html").
  • Call figure() untuk membuat plot dengan semua opsi, seperti title, tools, label dll.
  • Tambahkan renderers (disini menggunakan, Figure.line) visual dapat di custom seperti color, legend dan width dari plot.
  • Perintahkan Bokeh untuk show() atau save() hasilnya.

Langkah tiga dan empat dapat di ulang untuk membuat lebih dari satu plot. Contoh di bawah ini,

from bokeh.plotting import figure, output_file, show

# prepare some data
x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y0 = [i**2 for i in x]
y1 = [10**i for i in x]
y2 = [10**(i**2) for i in x]

# output to static HTML file
output_file("log_lines.html")

# create a new plot
p = figure(
   tools="pan,box_zoom,reset,save",
   y_axis_type="log", y_range=[0.001, 10**11], title="log axis example",
   x_axis_label='sections', y_axis_label='particles'
)

# add some renderers
p.line(x, x, legend="y=x")
p.circle(x, x, legend="y=x", fill_color="white", size=8)
p.line(x, y0, legend="y=x^2", line_width=3)
p.line(x, y1, legend="y=10^x", line_color="red")
p.circle(x, y1, legend="y=10^x", fill_color="red", line_color="red", size=6)
p.line(x, y2, legend="y=10^x^2", line_color="orange", line_dash="4 4")

# show the results
show(p)



Referensi