得分后卫 vs 小前锋
一家体育媒体机构将撰写一篇博客,比较得分后卫和小前锋在得分产出中的重要性。他们请您绘制一个散点图,分别用不同的图元颜色、大小和透明度展示这两个位置的场均得分与场均助攻。
nba 数据集已筛选出 "SG" 和 "SF",并为您预加载为两个 Bokeh 源对象:shooting_guards 和 small_forwards。同时已创建一个 HoverTool,用于显示 "player"、"team" 和 "field_goal_perc"。
本练习是课程的一部分
使用 Bokeh 进行交互式数据可视化
练习说明
- 使用
shooting_guards为"场均得分 vs 场均助攻"添加圆形图元,size设为 16 像素,fill_color设为红色,并将图元透明度相关的关键字参数设为0.2。 - 为小前锋的"得分 vs 场均助攻"添加圆形图元,填充为绿色,大小为 6 像素,图元透明度设为
0.6。
交互式实操练习
通过完成这段示例代码来试试这个练习。
TOOLTIPS = [("Name", "@player"), ("Team", "@team"), ("Field Goal %", "@field_goal_perc{0.2f}")]
fig = figure(x_axis_label="Assists", y_axis_label="Points", title="Shooting Guard vs Small Forward", tooltips=TOOLTIPS)
# Add glyphs for shooting guards
fig.circle(x="assists", y="points", source=shooting_guards, legend_label="Shooting Guard", ____=____, ____="____", ____=____)
# Add glyphs for small forwards
fig.circle(x="assists", y="points", source=small_forwards, legend_label="Small Forward", ____=____, ____="____", ____=____)
output_file(filename="sg_vs_sf.html")
show(fig)