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 example。它在bokeh0.11下运行得很好。在
如果像this这样的东西是在我对bokeh data table做了这件事之后,你就可以确定我使用了相同的源代码。在
要了解我的意思,一定要点击数据点。也可以按Shift键。在
相关问题 更多 >
编程相关推荐