点击呼叫按钮

2024-06-01 09:02:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个bokeh图表,它显示了几个字形,悬停工具在它们上面正常工作,给出了关于hover的非常有用的信息。在

我需要的是一种使信息持久化的方法,也就是说,不要在鼠标离开时消失。在

一个点击锁定对我来说很有用,但是有最新点击字形信息的链接表也是如此。在

一般来说,我可以注册一个clickjavascript回调函数,以使用所单击元素的数据源信息进行调用。在

有办法吗?在


Tags: 工具方法函数信息元素图表bokeh鼠标
2条回答

我试过基于this example。它在bokeh0.11下运行得很好。在

from bokeh.plotting import figure, output_notebook, show
from bokeh.io import output_file, show, vform
from bokeh.models import ColumnDataSource, HoverTool, CustomJS
from bokeh.models.widgets import DataTable, TableColumn
output_file("test.html")

# define some points and a little graph between them
x = [2, 3, 5, 6, 8, 7]
y = [6, 4, 3, 8, 7, 5]

p = figure(width=400, height=400, title='Hover over points')


cr = p.circle(x, y, color='olive', size=30, alpha=0.4, hover_color='olive', hover_alpha=1.0)

# Add a hover tool, that sets the link data for a hovered circle
code = """
var data = {'x0': [], 'y0': []};
var cdata = circle.get('data');
var indices = cb_data.index['1d'].indices;

for (i=0; i < indices.length; i++) {
    // pay attention to where x and y are defined, if you define them outside for loop, 
    // it will be updated at the same time you mouse hover off the target.
    // If you want to keep the last hover on result, put x and y inside for loop.
    x = [] 
    y = []
    idx = indices[i]
    x.push(cdata.x[idx]);
    y.push(cdata.y[idx]);
}
data_table.set('data', {
    'x' : x,
    'y' : y
});
""" 

source = ColumnDataSource({})

columns = [
        TableColumn(field="x", title="x"),
        TableColumn(field="y", title="y"),
    ]

data_table = DataTable(source=source, columns=columns, width=400, height=280)
callback = CustomJS(args={'circle': cr.data_source, 'data_table':data_table.source}, code=code)
p.add_tools(HoverTool(tooltips=None, callback=callback, renderers=[cr]))
layout = vform(p,data_table)
show(layout)

如果像this这样的东西是在我对bokeh data table做了这件事之后,你就可以确定我使用了相同的源代码。在

要了解我的意思,一定要点击数据点。也可以按Shift键。在

相关问题 更多 >