添加 LassoSelectTool

使用 Bokeh 进行交互式数据可视化

George Boorman

Core Curriculum Manager, DataCamp

检查器

 

  • 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...