1 - Interactive Data Visualization With Bokeh
1 - Interactive Data Visualization With Bokeh
Interactive Data
Visualization with
Bokeh
Interactive Data Visualization with Bokeh
What is Bokeh?
● Interactive visualization, controls, and tools
● Versatile and high-level graphics
● High-level statistical charts
● Streaming, dynamic, large data
● For the browser, with or without a server
● No JavaScript
Interactive Data Visualization with Bokeh
Interactive Data Visualization with Bokeh
See you in
the course!
INTERACTIVE DATA VISUALIZATION WITH BOKEH
Plo!ing with
Glyphs
Interactive Data Visualization with Bokeh
Typical usage
In [1]: from bokeh.io import output_file, show
In [5]: output_file('circle.html')
In [6]: show(plot)
Interactive Data Visualization with Bokeh
Glyph properties
● Lists, arrays, sequences of values
● Single fixed values
Markers
● asterisk()
● circle()
● circle_cross()
● circle_x()
● cross()
● diamond()
● diamond_cross()
● inverted_triangle()
● square()
● square_cross()
● square_x()
● triangle()
● x()
INTERACTIVE DATA VISUALIZATION WITH BOKEH
Let’s practice!
INTERACTIVE DATA VISUALIZATION WITH BOKEH
Additional Glyphs
Interactive Data Visualization with Bokeh
Lines
In [1]: from bokeh.io import output_file, show
In [3]: x = [1,2,3,4,5]
In [4]: y = [8,6,5,2,3]
In [7]: output_file('line.html')
In [8]: show(plot)
Interactive Data Visualization with Bokeh
In [3]: x = [1,2,3,4,5]
In [4]: y = [8,6,5,2,3]
In [8]: output_file('line.html')
In [9]: show(plot)
Interactive Data Visualization with Bokeh
Patches
● Useful for showing geographic regions
● Data given as “list of lists”
Interactive Data Visualization with Bokeh
Patches
In [1]: from bokeh.io import output_file, show
In [7]: output_file('patches.html')
In [8]: show(plot)
Interactive Data Visualization with Bokeh
Other glyphs
● annulus() ● patch()
● annular_wedge() ● patches()
● wedge()
● line()
● rect() ● multi_line()
● quad()
● vbar() ● circle()
● hbar() ● oval()
● ellipse()
● image()
● image_rgba() ● arc()
● image_url() ● quadratic()
● bezier()
INTERACTIVE DATA VISUALIZATION WITH BOKEH
Let’s practice!
INTERACTIVE DATA VISUALIZATION WITH BOKEH
Data Formats
Interactive Data Visualization with Bokeh
In [3]: x = [1,2,3,4,5]
In [4]: y = [8,6,5,2,3]
In [8]: output_file('basic.html')
In [9]: show(plot)
Interactive Data Visualization with Bokeh
NumPy Arrays
In [1]: from bokeh.io import output_file, show
In [7]: plot.line(x, y)
In [8]: output_file('numpy.html')
In [9]: show(plot)
Interactive Data Visualization with Bokeh
Pandas
In [1]: from bokeh.io import output_file, show
In [6]: plot.circle(flowers['petal_length'],
...: flowers['sepal_length'],
...: size=10)
In [7]: output_file('pandas.html')
In [8]: show(plot)
Interactive Data Visualization with Bokeh
In [3]: source.data
Out[3]: {'x': [1, 2, 3, 4, 5], 'y': [8, 6, 5, 2, 3]}
Interactive Data Visualization with Bokeh
In [3]: df.head()
Out[3]:
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
Let’s practice!
INTERACTIVE DATA VISUALIZATION WITH BOKEH
Customizing Glyphs
Interactive Data Visualization with Bokeh
Selection appearance
In [1]: plot = figure(tools='box_select, lasso_select')
Hover appearance
In [1]: from bokeh.models import HoverTool
Color mapping
In [1]: from bokeh.models import CategoricalColorMapper
Let’s practice!