所以,我只是链接出色的帖子, Two interactive bokeh plots: select a value in one graph and change the other 还有一个问题是否/如何单独(没有Bokeh服务器)完成,即仅通过JSCallbacks完成?
非常感谢!
答案 0 :(得分:0)
这是独立文档的JS回调版本(已在Bokeh 1.0.4上测试):
from bokeh.layouts import row
from bokeh.models import ColumnDataSource, CustomJS, TapTool
from bokeh.plotting import figure, show
import numpy as np
source_bars = ColumnDataSource({'x': [1, 2, 3], 'y': [2, 4, 1] , 'colnames': ['A', 'B', 'C']})
lines_y = [np.random.random(5) for i in range(3)]
plot1 = figure(tools = 'tap')
bars = plot1.vbar(x = 'x', top = 'y', source = source_bars, bottom = 0, width = 0.5)
plot2 = figure()
lines = plot2.line(x = 'x', y = 'y', source = ColumnDataSource({'x': np.arange(5), 'y': lines_y[0]}))
lines.visible = False
code = '''if (cb_data.source.selected.indices.length > 0){
lines.visible = true;
selected_index = cb_data.source.selected.indices[0];
lines.data_source.data['y'] = lines_y[selected_index]
lines.data_source.change.emit();
}'''
plots = row(plot1, plot2)
plot1.select(TapTool).callback = CustomJS(args = {'lines': lines, 'lines_y': lines_y}, code = code)
show(plots)
结果: