I have a simple scatter plot where I can select any points with the BoxSelectTool and the indices for the selected points are printed:
#!/usr/bin/env python
import numpy as np
from bokeh.plotting import figure, ColumnDataSource, curdoc
p = figure(title = “My chart”, tools=‘box_select’)
source = ColumnDataSource(
dict(
x=list(range(0, 10)),
y=list(np.random.normal(0, 1, 10)),
)
)
p.scatter(“x”, “y”,source=source, color=‘black’)
def update(attr, old, new):
inds = np.array(new['1d']['indices'])
print(inds)
source.on_change(‘selected’, update)
curdoc().add_root(p)
However, when I change the plot from scatter to line:
#!/usr/bin/env python
import numpy as np
from bokeh.plotting import figure, ColumnDataSource, curdoc
p = figure(title = “My chart”, tools=‘box_select’)
source = ColumnDataSource(
dict(
x=list(range(0, 10)),
y=list(np.random.normal(0, 1, 10)),
)
)
#p.scatter(“x”, “y”,source=source, color=‘black’)
p.line(“x”, “y”,source=source, color=‘black’)
def update(attr, old, new):
inds = np.array(new['1d']['indices'])
print(inds)
source.on_change(‘selected’, update)
curdoc().add_root(p)
In this case, nothing gets selected or printed when I use the BoxSelectTool. Any suggestions for how to get this to work? I can’t tell if this is an issue to be filed.