cb_data包含與當前懸停的字形相關的索引。然後,您可以使用它來索引您想要的任何目的的基礎數據。
from bokeh.plotting import figure, show
from bokeh.models import HoverTool, CustomJS, ColumnDataSource
top = [2, 3, 4]
bottom = [1, 2, 3]
left = [1, 2, 3]
right = [1.2, 2.5, 3.7]
data = {'top':top, 'bottom':bottom, 'left':left, 'right':right}
source = ColumnDataSource(data)
quad_plot = figure(plot_width=300, plot_height=300)
quad_plot.quad(top="top", bottom="bottom", left="left",
right="right",source=source, color="#B3DE69")
code = """
var hovered_ind = cb_data.index['1d'].indices[0];
var data = source.data
console.log(hovered_ind)
if(hovered_ind != undefined){
console.log('inside', hovered_ind)
var top = data['top'][hovered_ind]
var bottom = data['bottom'][hovered_ind]
var left = data['left'][hovered_ind]
var right = data['right'][hovered_ind]
console.log(top, bottom, left, right)
}
"""
callback = CustomJS(code=code, args={'source': source})
quad_plot.add_tools(HoverTool(tooltips=None, callback=callback))
show(quad_plot)
感謝您的回答!如果我使用'2d'或'3d',我會引用什麼? – Conic