简体   繁体   English

散景 - 如何点击和拖动?

[英]Bokeh - How to Click and Drag?

I would like to click-and-drag the scatter points the points of a bokeh scatter plot. 我想点击并拖动散点图散点图的点。 Any ideas how to do this? 任何想法如何做到这一点?

(edit: this is an example of what I'd like to do) (编辑:这是我想做的一个例子

For an example of a scatter, the code below generates the scatter plot chart found half-way through this page . 有关散点的示例,下面的代码会生成在此页面中间找到的散点图。

from bokeh.plotting import figure, output_file, show

# create a Figure object
p = figure(width=300, height=300, tools="pan,reset,save")

# add a Circle renderer to this figure
p.circle([1, 2.5, 3, 2], [2, 3, 1, 1.5], radius=0.3, alpha=0.5)

# specify how to output the plot(s)
output_file("foo.html")

# display the figure
show(p)

Multi-gesture edit tools are only a recent addition, landing in version 0.12.14 . 多手势编辑工具只是最近添加的, 登陆版本0.12.14 You can find much more information in the Edit Tools section of the User's Guide. 您可以在“用户指南”的“ 编辑工具”部分中找到更多信息。

Specifically to be able to move points as described in the OP, use the PointDrawTool : 特别是为了能够按照OP中的描述移动点,使用PointDrawTool

在此输入图像描述

Here is a complete example you can run that also has a data table showing the updated coordinates of the glyphs as they are moved (you will need to activate the tool in the toolbar first, it is off by default): 下面是一个完整的示例,您可以运行它还有一个数据表,显示字形在移动时的更新坐标(您需要先在工具栏中激活该工具,默认情况下它是关闭的):

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

output_file("tools_point_draw.html")

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

show(Column(p, table))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM