I'm trying to set up a bokeh plot where the user can click on the plot to add a point. I've seen this example which uses the BoxSelectTool
to add Rect
glyphs to the plot, however I'm looking for a way to add circle glyphs centered at the click location. I would also like to then send these points back to the server side of things. Anyone have any experience doing something similar?
Bokeh can be used to plot multiple lines on a graph. Plotting multiple lines on a graph can be done using the multi_line() method of the plotting module.
Bokeh is a Python library for creating interactive visualizations for modern web browsers. It helps you build beautiful graphics, ranging from simple plots to complex dashboards with streaming datasets.
This works for me in Bokeh version 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)
(to run it save this script as something.py and run in a cmd: bokeh serve something.py --show )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With