python - 如何在散景中突出显示另一个人物的线条?
问题描述
在下面的示例(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]]))
解决方案
有两种方法可以做到这一点。首先,您应该使用相同的源,并且它们会自动链接。其次,您可以使用带有索引的点击工具链接到其他图表。TapTool 可以使用 on_event 或 js_on_event
最后,你为什么要使用像'bokeh.io.show'这样的完整功能?你可以进口。此外,对于第二个选项,您应该使用 ColumnDataSource
推荐阅读
- excel - 为什么我会收到“类型不匹配”错误?
- mysql - 需要一些指导来优化 MySQL 中的报告
- gradle - 在 build.gradle 中如何提取和重用 Maven 存储库配置?
- sql - 执行 INNER JOIN 时查询返回错误值?
- mysql - 大量行的最佳存储?
- java - ElasticSearch 高级 API 使用自定义设置创建索引返回错误
- javascript - 对象加载成功但不显示
- ruby-on-rails - 检查一个时间范围是否在另一个时间范围和多少小时之间 Ruby on Rails
- amazon-web-services - AWS API Gateway 为 Web 应用程序引发 502 错误
- sql-server - 禁用表上的 CDC,但保留 CDC 表的历史记录