【发布时间】:2020-07-10 11:29:49
【问题描述】:
我正在尝试获取用户绘制的点的 xy 坐标。我想将它们作为字典、列表或 pandas DataFrame。
我在 Jupyter 中使用 Bokeh 2.0.2。会有一个背景图片(这不是本文的重点),在顶部,用户将创建我可以进一步使用的点。
下面是我设法到达的地方(带有一些虚拟数据)。我已经评论了一些我认为是我必须走的方向的行。但我似乎没有掌握它。
from bokeh.plotting import figure, show, Column, output_notebook
from bokeh.models import PointDrawTool, ColumnDataSource, TableColumn, DataTable
output_notebook()
my_tools = ["pan, wheel_zoom, box_zoom, reset"]
#create the figure object
p = figure(title= "my_title", match_aspect=True,
toolbar_location = 'above', tools = my_tools)
seeds = ColumnDataSource({'x': [2,14,8], 'y': [-1,5,7]}) #dummy data
renderer = p.scatter(x='x', y='y', source = seeds, color='red', size=10)
columns = [TableColumn(field="x", title="x"),
TableColumn(field="y", title="y")]
table = DataTable(source=seeds, columns=columns, editable=True, height=100)
#callback = CustomJS(args=dict(source=seeds), code="""
# var data = source.data;
# var x = data['x']
# var y = data['y']
# source.change.emit();
#""")
#
#seeds.x.js_on_change('change:x', callback)
draw_tool = PointDrawTool(renderers=[renderer])
p.add_tools(draw_tool)
p.toolbar.active_tap = draw_tool
show(Column(p, table))
【问题讨论】:
标签: python pandas callback bokeh