来自工具的Bokeh服务器回调

2024-09-27 07:35:12 发布

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

我对Python有点陌生,目前正在使用Bokeh进行交互式绘图可视化,在这里我需要显示多个相关图表。为了实现这一点,我使用bokeh服务器。

我一直在阅读文档和some examples,但是我找不到一个python回调(在服务器中执行)的例子,它是由绘图上的选择触发的。基本上我想做的是:

from bokeh.plotting import figure, curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource

TOOLS = "tap"
p = figure(title="Some Figure", tools=TOOLS)

source = ColumnDataSource(dict(x=[[1, 3, 2], [3, 4, 6, 6]], y=[[2, 1, 4], [4, 7, 8, 5]], name=['A', 'B']))

p.patches('x', 'y', source=source, color=["firebrick", "navy"], alpha=[0.8, 0.3], line_width=2)


def callback():
    print("TapTool callback executed on Patch {}")


??? <- some code here linking the taptool with the callback function defined above


curdoc().add_root(column(p))

然后在执行服务器并单击修补程序时:

2017-02-14 16:32:00,000 TapTool callback executed on Patch A

这种行为可以用bokeh来实现吗?


Tags: fromimport服务器绘图sourcecallbackbokehcolumn

热门问题