Difference between revisions of "Bokeh: Quick Start"

From OnnoWiki
Jump to navigation Jump to search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
Sumber: http://bokeh.pydata.org/en/latest/docs/quickstart.html
 
Sumber: http://bokeh.pydata.org/en/latest/docs/quickstart.html
 +
 +
 +
==Instalasi Anaconda==
 +
 +
Klik [[Python: Anaconda - Install | Cara Instalasi Anacoda]]
  
  
Line 6: Line 11:
 
Jika kita menggunakan Anaconda, kita dapat menggunakan
 
Jika kita menggunakan Anaconda, kita dapat menggunakan
  
 +
easy_install -U pip
 
  conda install bokeh
 
  conda install bokeh
  
 
Ini akan menginstalasi secara lengkap, tanpa pusing.
 
Ini akan menginstalasi secara lengkap, tanpa pusing.
  
Jika kita cukup Percaya Diri (PD) bahwa kita mempunyai semua dependensi yang dibutuhkan seperti NumPy, Pandas, dan Redis, maka kita dapat menggunakan,
+
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
 
  pip install bokeh
  
Getting Started
+
==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
  
Bokeh is a large library that exposes many capabilities, so this section is only a quick tour of some common Bokeh use-cases and workflows. For more detailed information please consult the full User Guide.
+
cd /var/www/html
  
Let’s begin with some examples.
+
Buat file
  
Plotting some data in basic Python lists as a line chart including zoom, pan, resize, save, and other tools is simple and straightforward:
+
vi /var/www/html/lines.py
  
from bokeh.plotting import figure, output_file, show
+
Isi dengan
  
 +
from bokeh.plotting import figure, output_file, show
 +
 
  # prepare some data
 
  # prepare some data
 
  x = [1, 2, 3, 4, 5]
 
  x = [1, 2, 3, 4, 5]
Line 38: Line 54:
 
   
 
   
 
  # show the results
 
  # show the results
  show(p)
+
  # 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.
  
When you execute this script, you will see that a new output file "lines.html" is created, and that a browser automaticaly opens a new tab to display it. (For presentation purposes we have included the plot output directly inline in this document.)
+
Langkah tiga dan empat dapat di ulang untuk membuat lebih dari satu plot. Contoh di bawah ini,
 
 
The basic steps to creating plots with the bokeh.plotting interface are:
 
 
 
* Prepare some data (in this case plain python lists).
 
* Tell Bokeh where to generate output (in this case using output_file(), with "lines.html" as the filename to save as).
 
* Call figure() to create a plot with some overall options like title, tools and axes labels.
 
* Add renderers (in this case, Figure.line) for our data, with visual customizations like colors, legends and widths to the plot.
 
* Ask Bokeh to show() or save() the results.
 
 
 
Steps three and four can be repeated to create more than one plot. See some examples of this below.
 
 
 
The bokeh.plotting interface is also quite handy if we need to customize the output a bit more by adding more data series, glyphs, logarithmic axis, etc. It’s also possible to easily combine multiple glyphs together on one plot as shown below:
 
 
 
from bokeh.plotting import figure, output_file, show
 
  
 +
from bokeh.plotting import figure, output_file, show
 +
 
  # prepare some data
 
  # prepare some data
 
  x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
 
  x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
Line 91: Line 107:
  
 
 
 
 
 
 
 
Jupyter Notebooks
 
 
At this point we should mention Jupyter (formerly IPython) notebooks.
 
 
Jupyter notebooks are a fantastic tool for exploratory data analysis, and they are widely used across the “PyData” community. Bokeh integrates seamlessly with Jupyter notebooks. To view the above examples in a notebook, you would only change output_file() to a call to output_notebook() instead.
 
 
A large number of static examples may be viewed directly online at the Bokeh NBViewer Gallery.
 
 
The Bokeh GitHub repository also has a number of example notebooks in the examples/plotting/notebook/ directory. After cloning the repository, navigate there and run:
 
 
ipython notebook
 
 
You can open and interact with any of the notebooks listed in the index page that automatically opens up. In particular, you might check out the interact_basic and interact_numba examples that show how Bokeh can be used together with Jupyter interactive widgets.
 
 
 
 
  
  

Latest revision as of 05:44, 23 February 2016

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