Highlighting and contrasting

Interactive Data Visualization with Bokeh

George Boorman

Core Curriculum Manager, DataCamp

Vectorizing glyph size

sizes = nba["points"] / 50

fig = figure(x_axis_label="Assists", y_axis_label="Points") fig.circle(x=nba["assists"], y=nba["points"], fill_color="purple", radius=sizes)
output_file(filename="glyph_vectorization.html") show(fig)
Interactive Data Visualization with Bokeh

Different sizes

radii_50

radii_25

Interactive Data Visualization with Bokeh

Palettes

from bokeh.palettes import Inferno3

inferno

from bokeh.palettes import Colorblind4

colorblind

from bokeh.palettes import __palettes__
__palettes__[:8]
['Accent3',
 'Accent4',
 'Accent5',
 'Accent6',
 'Accent7',
 'Accent8',
 'Blues3',
 'Blues4']
Interactive Data Visualization with Bokeh

Color mapping and color bars

linear_cmap

Interactive Data Visualization with Bokeh

Linear color mapping

from bokeh.transform import linear_cmap

from bokeh.palettes import YlOrBr8
from bokeh.models import ColorBar
mapper = linear_cmap(field_name="points", palette=YlOrBr8, low=min(nba["points"])), high=max(nba["points"]))
fig = figure(x_axis_label="Assists", y_axis_label="Points") fig.circle(x="assists", y="points", source=source, fill_color=mapper, line_color=mapper)
color_bar = ColorBar(color_mapper=mapper["transform"], width=8)
fig.add_layout(color_bar, "right")
output_file(filename="linear_cmap.html") show(fig)
Interactive Data Visualization with Bokeh

Linear color map scatter plot

linear_cmap

Interactive Data Visualization with Bokeh

Factor color mapping

from bokeh.transform import factor_cmap
from bokeh.palettes import Category10_5

positions = ["PG", "SG", "SF", "PF", "C"] fig = figure(x_axis_label="Rebounds", y_axis_label="Points") fig.circle(x="rebounds", y="points", source=source,
fill_color=factor_cmap("position", palette=Category10_5, factors=positions),
legend_field="position")
output_file(filename="factor_cmap.html") show(fig)
Interactive Data Visualization with Bokeh

Color categorized bar plot

factor_cmap

Interactive Data Visualization with Bokeh

Let's practice!

Interactive Data Visualization with Bokeh

Preparing Video For Download...