Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Multilines using Lasso Tool

I have a multiline plot in bokeh and I'd like to select some multilines using the lasso tool. This does not work by default: The lasso tool does not select any lines.

from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.models import MultiLine

plot = figure(plot_width=400, plot_height=400, tools="lasso_select")
renderer = plot.multi_line([[1, 2, 3, 4, 5], [0,1]], [[2, 5, 8, 2, 7], [1,0]])

selected_circle = MultiLine(line_alpha=0.5, line_color='firebrick')
nonselected_circle = MultiLine(line_alpha=1, line_color='red')

renderer.selection_glyph = selected_circle
renderer.nonselection_glyph = nonselected_circle

show(plot)

Of course, the question is how a line should be considered as selected: Is it selected if one point of the line is in the lasso area or if all points are in the lasso area?

I tried to add some javascript code to change the behavior of the lasso tool but apparently multilines do not work analogous to simple data points:

This code...

on_lasso = CustomJS(args=dict(), code='''
    console.log(cb_obj.selected);
''')

lasso = LassoSelectTool(callback=on_lasso)
plot = figure(plot_width=800, plot_height=600, tools=[lasso])

...tells me that cb_obj.selected is undefined for some reason.

Any help would be greatly appreciated!

PS: I use bokeh v0.13.0

like image 314
user3637203 Avatar asked Aug 07 '18 08:08

user3637203


1 Answers

Unfortunately selection methods other than tap seem to be unavailable for MultiLine. To give you a bit of history, tap support for MultiLine is implemented in bokeh v0.12.2; see bokeh issue #3110 in GitHub.

However, using your CustomJs code for lasso in debug mode (export BOKEH_DEV=1) I get the following in console log:

[bokeh] 'poly' selection not available for MultiLine  bokeh.js:13478

This warning is only logged once, see code, and easy to miss.

I recommend opening a feature request in Bokeh GitHub.

like image 56
Ghasem Naddaf Avatar answered Sep 28 '22 06:09

Ghasem Naddaf