添加 HoverTool
该机构正在撰写一篇关于按场上位置划分的篮球表现的博客。他们希望聚焦助攻与抢断,并让读者可以将鼠标悬停在图元上,查看球员姓名、所打位置以及所属球队。
您将把已预加载的 nba 数据集转换为 Bokeh 的 source 对象,然后为图表添加工具提示。
本练习是课程的一部分
使用 Bokeh 进行交互式数据可视化
练习说明
- 导入
ColumnDataSource。 - 由
nbaDataFrame 创建source。 - 完成
TOOLTIPS的创建,按顺序添加名为"Position"和"Team"的标签,分别来自source中相应的列,并将TOOLTIPS添加到图形中。 - 为 x 轴的
"assists"和 y 轴的"steals"添加圆形图元,补全source参数。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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)