bokeh can provide interactive visualization for modern web browsers. elegant, concise, vesatile graphics, *afford high-performacne interactiivity onver lagerge or streaming datasets.
bokeh provide two interface levels:
- bokeh.models: low-level interface provide most flexibility
- bokeh.plotting: higher-level interface centered around composing visual glyphs.
this focus on bokeh.plotting
.
installation
# recommend way
# conda install deps, and exmaples in *examples/* subdirectory
conda install bokeh
# using pip, you need install ~numpy~ and so on.
pip install bokeh
get-starting
- [] TODO output bokeh plot to or-babel result
you can download sample-date and example from bokeh
bokeh sampledata
the general steps of bokeh.ploting:
- prepare data
- tell bokeh where to generate output(file or notebook)
- call figure() to create a plot figure
- add renderers, to add renderers to figure, such as
fig.line()
- call
show()
orsave()
to output results
from bokeh.plotting import figure, output_file, show, output_notebook
# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# output to static html file
# ??? how to use in web-server like flask.
# output_file("lines.html")
# output_notebook()
# create a new plot with a litter 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_label="Temp.", line_width=2)
# show the results
show(p)
bokeh work well with jupyter-notebook. jupyter-notebook is the common tool for exploratory data analysis, widely used across the pyData community. you can view online Bokeh NBViewer Gallery, or examples/howto in the Bokeh Repo.
TODO notebook:
- bokeh interact with jupyter’s dropdown and sliders
- use Numba to efficiently perform image processing
bokeh notebook cannot display in Github preveiw, cause bokeh using javascript for display which was scrub by Github.
concept
Plot
central concept in Bokeh, containers that hold all the various objects (renderers, guides, data, and tools)
??? the figure()
return object
Glyph
basic visual marks that bokeh can display.
??? the line()
plot()
returns
- at low-level, there are glyph objects, such as
Line
on thebokeh.models
interface - at higher-level, there are glyph methods such as
line()
provided bybokeh.plotting
interface.
Guides and Annotations
tools component that aid presentation or help user make comparisions.
Guide
visual aids help user judge distances, angles etc. such as grid-lines(珊格线) or bands(???布林线), axes(轴线, linear, log, datetime)
annotations
visual aids that label or name parts of the plot. such as titles, legends(图例) etc.
Ranges
the data-space bounds of a plot.
by default of bokeh.plotting
interface,
it give DataRange1d
that try to automatically set the plot bounds to encompass all the available data.
p = figure(x_range=[0, 10], y_range=(10, 20))
Resources
the generate bokeh output, such as html-file or notebook.
bokeh default load bokehjs from cdn.bokeh.org, you can embedeed it static by output_file(mode="inline")
TODO more-exampels
Vectorized colors and sizes
Linked Panning and Brushing
DateTiem axes
TODO Bokeh applications
check-over this run bokeh server
bokeh comes with an optional server-component, the Bokeh Serevr.
it affords many novel and powerful capabilities:
- UI widgets and plot selections driving computations and plot updates.
- Intelligent server-side downsampling of large datasets.
- Streaming data automatically updating plots.
- Sophisticated glyph re-writing and transformations for “Big Data”.
- Plot and dashboard publishing for wider audiences.