bokehjs - 测量散景中直方图之间的距离
问题描述
我用直方图生成散景图。我需要测量直方图之间的距离。我选择 Taptool 通过以下代码完成这项工作。但它不起作用,JS 控制台显示 selected_x 是“未定义”。有没有可能做的工作?
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="navy", line_color="white", alpha=0.5)
x_list = []
for i in range(1):
callback = CustomJS(args=dict(source=source_hist, x_list=x_list), code='''
var selected_x = source.data.hist[source.selected];
if (x_list.length == 0) // indicates that this is the first point selected
{
console.log("First point selected is "+selected_x)
x_list.push(selected_x);
}
else // this is the second point selected
{
console.log("Second point is " + selected_x + ". Distance is " + (selected_x - x_list[0])*0.3125 + " ms")
x_list.pop();
}
''')
p.add_tools(TapTool(callback=callback))