各位置的罰球命中率
機構還要求你提供最後一個圖表。你將使用 factor_cmap 建立一張散佈圖,呈現罰球命中率與平均得分,並以不同顏色顯示每個球員位置。
名為 source 的資料來源物件已由 nba 資料集建立並預先載入。變數 TOOLTIPS(包含球員姓名)也已建立,將滑鼠移到圖上時即可查看。
本練習屬於課程
使用 Bokeh 製作互動式資料視覺化
練習說明
- 匯入
Category10_5與factor_cmap。 - 建立
positions,其內容為清單:"PG"、"SG"、"SF"、"PF"、"C"。 - 在
fig.circle()中,將legend_field參數設為"position",並完成fill_color參數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import modules
____
____
# Create positions
positions = ["____", "____", "____", "____", "____"]
fig = figure(x_axis_label="Free Throw Percentage", y_axis_label="Points", title="Free Throw Percentage vs. Average Points", tooltips=TOOLTIPS)
# Add circle glyphs
fig.circle(x="free_throw_perc", y="points", source=source, legend_field="____", fill_color=factor_cmap("____", palette=____, factors=____))
output_file(filename="average_points_vs_free_throw_percentage.html")
show(fig)