Hello,
i have bokeh scatter plot and i want when i’m clicking on a dot to get the data about that dot. i have a server instance of bokeh.
i documentation it is not well explained that part
Hello,
i have bokeh scatter plot and i want when i’m clicking on a dot to get the data about that dot. i have a server instance of bokeh.
i documentation it is not well explained that part
You can save the code as main.py and run from terminal:
bokeh serve --show main.py
``
The code:
from bokeh.plotting import curdoc, figure
from bokeh.models import ColumnDataSource, TapTool
from bokeh.models.widgets import TextInput
source = ColumnDataSource(dict(x = [3, 6], y = [5, 5], color = [‘red’, ‘green’], text = [‘left’, ‘right’]))
text = TextInput(value = ‘’)
plot = figure(title = ‘Plot’, tools = “tap”)
circles = plot.circle(x = ‘x’, y = ‘y’, fill_color = ‘color’, source = source, size = 100, fill_alpha = 0.5)
def function_on_change(attr, old, new):
try:
index = source.selected[“1d”][“indices”][0]
action = source.data[“text”][index]
plot.title.text = "%s: x=%s, y=%s" % (action, str(source.data['x'][index]), source.data['y'][index])
except IndexError:
plot.title.text = ''
source.on_change(‘selected’, function_on_change)
curdoc().add_root(plot)
``
On Tuesday, January 29, 2019 at 3:01:50 PM UTC+1, Iulian Craciun wrote:
Hello,
i have bokeh scatter plot and i want when i’m clicking on a dot to get the data about that dot. i have a server instance of bokeh.
i documentation it is not well explained that part