我正在尝试在 jupyter 笔记本的一个单元格中使用 PointDrawTool 在散景图中绘制两个点,然后在另一个单元格中使用绘制点的坐标。
我从这个例子开始:
https://docs.bokeh.org/en/latest/docs/user_guide/examples/tools_point_draw.html
...并稍作修改以在笔记本内输出:
from bokeh.plotting import figure, output_file, show, Column
from bokeh.models import DataTable, TableColumn, PointDrawTool, ColumnDataSource
from bokeh.io import output_notebook
output_notebook()
p = figure(
title='scope')
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
#p.line(range(len(y)),y)
show(Column(p, table))
我在图中画了两个点。
在另一个笔记本单元格中:
len(source.data["x"])
它返回 3。换句话说,我可以访问初始化“源”的三个点,但不能访问之后绘制的任何点。
有任何想法吗?
