Plot Bokeh-使用编辑工具时获取更新的数据

Plot Bokeh-使用编辑工具时获取更新的数据,plot,bokeh,interactive,Plot,Bokeh,Interactive,最近,Bokeh中增加了多个手势。例如,使用下面的脚本,我可以使用PointDrawTool在jupyter笔记本中以交互方式绘制点。我的问题是,如何将生成或编辑的点的更新数据获取到numpy数组或类似的数据结构中 from bokeh.plotting import figure, output_file, show, Column from bokeh.models import DataTable, TableColumn, PointDrawTool, ColumnDataSource

最近,Bokeh中增加了多个手势。例如,使用下面的脚本,我可以使用PointDrawTool在jupyter笔记本中以交互方式绘制点。我的问题是,如何将生成或编辑的点的更新数据获取到numpy数组或类似的数据结构中

from bokeh.plotting import figure, output_file, show, Column
from bokeh.models import DataTable, TableColumn, PointDrawTool, ColumnDataSource
from bokeh.io import output_notebook

# Direct output to notebook
output_notebook()

p = figure(x_range=(0, 10), y_range=(0, 10), tools=[],
           title='Point Draw Tool')
p.background_fill_color = 'lightgrey'

source = ColumnDataSource({
    'x': [1, 5, 9], 'y': [1, 5, 9], 'color': ['red', 'green', 'yellow']
})

renderer = p.scatter(x='x', y='y', source=source, color='color', size=10)
columns = [TableColumn(field="x", title="x"),
           TableColumn(field="y", title="y"),
           TableColumn(field='color', title='color')]
table = DataTable(source=source, columns=columns, editable=True, height=200)

draw_tool = PointDrawTool(renderers=[renderer], empty_value='black')
p.add_tools(draw_tool)
p.toolbar.active_tap = draw_tool

handle = show(Column(p, table), notebook_handle=True)

使用这种显示绘图的方法不会在Python和JS之间提供同步。要解决这个问题,可以使用bookeh服务器,如前所述。通常使用commnad:

bokeh serve --show myapp.py
然后,您可以将此应用程序嵌入到jupyter中。对我来说,这是非常不礼貌的,所以我开始寻找其他的解决办法

可以从jupyter笔记本运行bookeh应用程序,您可以找到示例

您的问题的示例代码如下所示:

from bokeh.plotting导入图形,输出\u笔记本,显示,列
从bokeh.models导入DataTable、TableColumn、PointDrawTool、ColumnDataSource
输出_笔记本()
def修改_文件(文件):
p=图(x_范围=(0,10),y_范围=(0,10),工具=[],
title='Point Draw Tool')
p、 背景\填充\颜色='浅灰色'
source=ColumnDataSource({
‘x’:[1,5,9],‘y’:[1,5,9],‘颜色’:[‘红色’、‘绿色’、‘黄色’]
})
渲染器=p.scatter(x='x',y='y',source=source,color='color',size=10)
columns=[TableColumn(field=“x”,title=“x”),
TableColumn(field=“y”,title=“y”),
TableColumn(field='color',title='color')]
table=DataTable(source=source,columns=columns,editable=True,height=200)
绘制工具=点绘制工具(渲染器=[渲染器],空值='黑色')
p、 添加工具(绘制工具)
p、 toolbar.active\u点击=绘制工具
文件添加_根(列(p,表))
显示(修改单据)