Adding a HoverTool
The agency is producing a blog about basketball performance by position. They want to hone in on assists and steals, giving their viewers the ability to hover over glyphs to find out who a player is, what position they play, and which team they play for.
You will convert the nba dataset, which has been preloaded, into a Bokeh source object, then add tooltips to a plot.
This exercise is part of the course
Interactive Data Visualization with Bokeh
Exercise instructions
- Import
ColumnDataSource. - Create
sourcefrom thenbaDataFrame. - Complete the creation of
TOOLTIPS, adding labels named"Position"and"Team", in that order, from the relevant columns ofsource, and addTOOLTIPSto the figure. - Add circle glyphs for
"assists"on the x-axis and"steals"on the y-axis, completing thesourceargument.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import ColumnDataSource
from ____.____ import ____
# Create source
source = ____(data=____)
# Create TOOLTIPS and add to figure
TOOLTIPS = [("Name", "@player"), ("____", "____"), ("____", "____")]
fig = figure(x_axis_label="Assists", y_axis_label="Steals", tooltips=____)
# Add circle glyphs
fig.circle(x="____", y="____", source=____)
output_file(filename="first_tooltips.html")
show(fig)