Adding style

Interactive Data Visualization with Bokeh

George Boorman

Core Curriculum Manager, DataCamp

Bokeh themes

  • caliber
  • dark_minimal
  • light_minimal
  • night_sky
  • contrast
1 http://docs.bokeh.org/en/latest/docs/user_guide/styling.html#using-themes
Interactive Data Visualization with Bokeh

Using themes

from bokeh.io import curdoc

curdoc().theme = "dark_minimal"
fig = figure(x_axis_label="Assists", y_axis_label="Points") fig.circle(x=nba["assists"], y=nba["points"]) output_file("dark_minimal.html") show(fig)

dark_minimal_nba_scatter

Interactive Data Visualization with Bokeh

Subsetting data

east = nba.loc[nba["conference"] == "East"]
west = nba.loc[nba["conference"] == "West"]
print(nba.columns, '\n', east.shape, '\n', west.shape)
Index(['player', 'position', 'minutes', 'field_goal_perc', 'three_point_perc', 'free_throw_perc', 
       'rebounds', 'assists', 'steals', 'blocks', 'points', 'team', 'conference'],
        dtype='object') 
(211, 13) 
(215, 13)
Interactive Data Visualization with Bokeh

Customizing color

fig = figure(x_axis_label="Assists per Game", y_axis_label="Points per Game")

fig.circle(x=east["assists"], y=east["points"], color="blue")
fig.circle(x=west["assists"], y=west["points"], color="red")
output_file(filename="east_vs_west.html") show(fig)

east_vs_west

Interactive Data Visualization with Bokeh

Adding a legend

fig = figure(x_axis_label="Assists per Game", y_axis_label="Points per Game")

fig.circle(x=east["assists"], y=east["points"], color="blue", legend_label="East")
fig.circle(x=west["assists"], y=west["points"], color="red", legend_label="West")
output_file(filename="east_vs_west_with_legend.html") show(fig)

east_vs_west_legend

Interactive Data Visualization with Bokeh

Glyph types

  • square
    • square

 

  • triangle
    • triangle

 

  • diamond
    • diamond
fig = figure(x_axis_label='Minutes Played', 
             y_axis_label="Points Per Game")

fig.square(x=nba["minutes_played"], y=nba["points_per_game"])
output_file(filename="nba_points.html") show(fig)

nba_square_scatter

Interactive Data Visualization with Bokeh

Multiple glyphs

fig = figure(x_axis_label="Assists per Game", y_axis_label="Points per Game")

fig.diamond(x=east["assists"], y=east["points"], color="blue", legend_label="Eastern Conference")
fig.triangle(x=west["assists"], y=west["points"], color="red", legend_label="Western Conference")
output_file(filename="multiple_glyphs.html") show(fig)

nba_multiple_glyphs

Interactive Data Visualization with Bokeh

The dataset

print(melb.columns)
Index(['rooms', 'type', 'price', 'date', 'distance', 'bedrooms', 'bathrooms',
       'car', 'land_area', 'building_area', 'year_built', 'council_area',
       'region'],
      dtype='object')
print(melb.shape)
(13580, 13)
Interactive Data Visualization with Bokeh

Let's practice!

Interactive Data Visualization with Bokeh

Preparing Video For Download...