開始使用免費開始

加入 HoverTool

代理商正要撰寫一篇依照場上位置分析籃球表現的部落格文章。他們想聚焦助攻與抄截,並讓讀者能將滑鼠移到圖元上,就能看到球員姓名、所屬位置,以及效力球隊。

你將把已預先載入的 nba 資料集轉成 Bokeh 的 source 物件,然後在圖上加入工具提示。

本練習屬於課程

使用 Bokeh 製作互動式資料視覺化

檢視課程

練習說明

  • 匯入 ColumnDataSource
  • nba DataFrame 建立 source
  • 完成 TOOLTIPS 的建立,依序從 source 中相關欄位加入名為「Position」與「Team」的標籤,並將 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)
編輯並執行程式碼