首页 文章

散景 - 如何点击和拖动?

提问于
浏览
5

我想点击并拖动散点图散点图的点 . 任何想法如何做到这一点?

(编辑:这是an example我想做的事情)

对于散射的示例,下面的代码生成在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)

1 回答

  • 4

    多手势编辑工具只是最近添加的,landing in version 0.12.14 . 您可以在“用户指南”的Edit Tools部分中找到更多信息 .

    具体为能够按照OP中的描述移动点,使用PointDrawTool

    enter image description here

    下面是一个完整的示例,您可以运行它还有一个数据表,显示字形在移动时的更新坐标(您需要先在工具栏中激活该工具,默认情况下它是关闭的):

    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))
    

相关问题