首页 > 解决方案 > 如何在散景中突出显示另一个人物的线条?

问题描述

在下面的示例(Bokeh 2.3.3)中,当我将鼠标悬停在一条线(Alice 的销售)上方时,线宽会增加。如何同时使另一条线(爱丽丝的收视率)变宽?

import random

import bokeh.io
import bokeh.palettes
import bokeh.layouts
import bokeh.plotting

months = list(range(12))
quarters = list(range(4))

sales = {
    'alice': [random.randint(0,100) for _ in months],
    'bob': [random.randint(0,100) for _ in months],
}
ratings = {
    'alice': [random.randint(0,5) for _ in quarters],
    'bob': [random.randint(0,5) for _ in quarters],
}

TOOLS = 'hover'

f1 = bokeh.plotting.figure(title='sales', plot_height=200, tools=TOOLS)
f1.line(months, sales['alice'], name='alice', hover_line_width=3)
f1.line(months, sales['bob'], name='bob', hover_line_width=3)

f2 = bokeh.plotting.figure(title='ratings', plot_height=200,tools=TOOLS)
f2.line(quarters, ratings['alice'], name='alice', hover_line_width=3)
f2.line(quarters, ratings['bob'], name='bob', hover_line_width=3)

# hover callback (?)

bokeh.io.show(bokeh.layouts.gridplot([[f1],[f2]]))

标签: pythonbokeh

解决方案


有两种方法可以做到这一点。首先,您应该使用相同的源,并且它们会自动链接。其次,您可以使用带有索引的点击工具链接到其他图表。TapTool 可以使用 on_event 或 js_on_event

最后,你为什么要使用像'bokeh.io.show'这样的完整功能?你可以进口。此外,对于第二个选项,您应该使用 ColumnDataSource


推荐阅读