加入 LassoSelectTool

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

George Boorman

Core Curriculum Manager, DataCamp

檢視工具(Inspectors)

 

  • CrosshairTool
    • crosshair 十字準線工具

 

 

  • HoverTool
    • hover 滑鼠暫留工具

CrosshairTool

1 https://docs.bokeh.org/en/latest/docs/user_guide/tools.html#userguide-tools-inspectors
使用 Bokeh 製作互動式資料視覺化

Bokeh 資料來源物件

from bokeh.models import ColumnDataSource

source = ColumnDataSource(data=nba)
fig = figure(x_axis_label="Minutes Played", y_axis_label="Points Per Game")
fig.circle(x="assists", y="points", source=source)
output_file(filename="ColumnDataSource.html") show(fig)

nba_scatter

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

設定 HoverTool

from bokeh.models import ColumnDataSource
source = ColumnDataSource(data=nba)

TOOLTIPS = [("Name", "@player"), ("Team", "@team")]
fig = figure(x_axis_label="Assists", y_axis_label="Points",
tooltips=TOOLTIPS)
fig.circle(x="assists", y="points", source=source) output_file("name_and_team.html") show(fig)
使用 Bokeh 製作互動式資料視覺化

HoverTool 成果示範

HoverTool

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

顯示數值資料

TOOLTIPS = [("Name", "@player"), ("Team", "@team"),

("Points", "@points"), ("Assists", "@assists")]
fig = figure(x_axis_label="Assists", y_axis_label="Points", tooltips=TOOLTIPS) fig.circle(x="assists", y="points", source=source) output_file("hovertool.html") show(fig)

未格式化的 HoverTool

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

格式化 HoverTool

TOOLTIPS = [("Name", "@player"), ("Team", "@team"),

("Points", "@points{0.2f}"), ("Assists", "@assists{0.2f}")]
fig = figure(x_axis_label="Assists", y_axis_label="Points", tooltips=TOOLTIPS) fig.circle(x="assists", y="points", source=source) output_file("formatted_hovertool.html") show(fig)

已格式化的 HoverTool

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

一起來練習吧!

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

Preparing Video For Download...