Difference between revisions of "Bokeh: Quick Start"

From OnnoWiki
Jump to navigation Jump to search
(New page: Sumber: http://bokeh.pydata.org/en/latest/docs/quickstart.html Quick Installation There are a few different ways to install Bokeh. If you are using the Anaconda Python distribution (w...)
 
 
(8 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
  
 +
==Instalasi Anaconda==
  
Quick Installation
+
Klik [[Python: Anaconda - Install | Cara Instalasi Anacoda]]
  
There are a few different ways to install Bokeh.
 
  
If you are using the Anaconda Python distribution (which is recommended), enter this command at a Bash or Windows command prompt:
+
==Instalasi==
  
conda install bokeh
+
Jika kita menggunakan Anaconda, kita dapat menggunakan
  
This installs all the dependencies that you need to be ready to run Bokeh and we strongly recommend using it. It reduces the installation effort to nearly zero on any platform and configuration (including Windows). It also installs the examples into the examples/ subdirectory of your Anaconda (or miniconda) installation directory.
+
easy_install -U pip
 +
conda install bokeh
  
If you are confident that you have dependencies such as NumPy, Pandas, and Redis installed, then you can also use pip at the command line:
+
Ini akan menginstalasi secara lengkap, tanpa pusing.
  
pip install bokeh
+
Jika kita cukup Percaya Diri (PD) bahwa kita mempunyai semua dependensi yang bidiagonal seperti NumPy, Pandas, dan Redis, maka kita dapat menggunakan,
  
Note
+
easy_install -U pip
 +
pip install bokeh
  
The pip method does not install the examples. Clone the Git repository and look in the examples/ directory of the checkout to see examples.
+
==Instalasi Web Server==
  
Windows users, see Notes for Windows Users in the Installation section.
+
sudo apt-get install apache2 php5 php5-xmlrpc php5-mysql \
Getting Started
+
php5-gd php5-cli php5-curl mysql-client mysql-server
  
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.
+
==Contoh Line Chart==
  
Let’s begin with some examples.
+
Lakukan
  
Plotting some data in basic Python lists as a line chart including zoom, pan, resize, save, and other tools is simple and straightforward:
+
cd /var/www/html
  
from bokeh.plotting import figure, output_file, show
+
Buat file
  
# prepare some data
+
vi /var/www/html/lines.py
x = [1, 2, 3, 4, 5]
 
y = [6, 7, 2, 4, 5]
 
  
# output to static HTML file
+
Isi dengan
output_file("lines.html", title="line plot example")
 
  
# create a new plot with a title and axis labels
+
from bokeh.plotting import figure, output_file, show
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')
+
 +
# 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)
  
# add a line renderer with legend and line thickness
+
Jalankan
p.line(x, y, legend="Temp.", line_width=2)
 
  
# show the results
+
cd /var/www/html
show(p)
+
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").
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.)
+
* 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.
The basic steps to creating plots with the bokeh.plotting interface are:
+
* Perintahkan Bokeh untuk show() atau save() hasilnya.
 
 
    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
 
 
 
# 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
+
Langkah tiga dan empat dapat di ulang untuk membuat lebih dari satu plot. Contoh di bawah ini,
show(p)
 
  
+
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)
  
 
 
 
 
 
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