点击时在散景图上添加一个点

时间:2016-03-13 18:34:32

标签: javascript python bokeh

我试图设置散景图,用户可以点击图表添加一个点。我已经看到this example使用BoxSelectToolRect字形添加到绘图中,但是我正在寻找一种方法来添加以点击位置为中心的圆形字形。我还想将这些要点发送回服务器端。有没有经验做类似的事情?

1 个答案:

答案 0 :(得分:3)

这适用于Bokeh版本0.12.13:

from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, Column
from bokeh.io import curdoc
from bokeh.events import DoubleTap

coordList=[]

TOOLS = "tap"
bound = 10
p = figure(title='Double click to leave a dot.',
           tools=TOOLS,width=700,height=700,
           x_range=(-bound, bound), y_range=(-bound, bound))

source = ColumnDataSource(data=dict(x=[], y=[]))   
p.circle(source=source,x='x',y='y') 

#add a dot where the click happened
def callback(event):
    Coords=(event.x,event.y)
    coordList.append(Coords) 
    source.data = dict(x=[i[0] for i in coordList], y=[i[1] for i in coordList])        
p.on_event(DoubleTap, callback)

layout=Column(p)

curdoc().add_root(layout)

(运行它将此脚本保存为something.py并在cmd中运行:散景服务于something.py - show)

enter image description here