Get startedGet started for free

Adding a color bar

The agency has requested you include a ColorBar so people viewing the plot will understand the thresholds at which the glyph color changes.

The figure from the previous exercise, a mapper, and glyphs, have all been provided for you.

This exercise is part of the course

Interactive Data Visualization with Bokeh

View Course

Exercise instructions

  • Import ColorBar.
  • Create color_bar using the relevant key from mapper, and set width to 8 pixels.
  • Add color_bar to the figure's layout on the right-hand side.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import ColorBar
____

mapper = linear_cmap(field_name="assists", palette=RdBu8, low=min(nba["assists"]), high=max(nba["assists"]))
fig = figure(x_axis_label="Steals", y_axis_label="Assists", title="Steals vs. Assists")
fig.circle(x="steals", y="assists", source=source, color=mapper)

# Create the color_bar
color_bar = ____(color_mapper=____, width=____)

# Update layout with color_bar on the right
fig.____(____, "____")
output_file(filename="steals_vs_assists_color_mapped.html")
show(fig)
Edit and Run Code