Select Regions of Line Plot with BoxSelectTool

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.

Hi,

Line glyphs currently only support hit testing by point and by span. There's not some huge technical hurdle, but it's never be exactly clear to me what the right policy for hit testing lines against rects should be. Is it sufficient to have any part of a line in the box? Or does all of a line have to be contained? I don't see an issue for this so I'd suggest opening one on GH and discussing your use case so that maybe we can hash out what the right behavior is.

Thanks,

Bryan

···

On Mar 16, 2017, at 09:27, [email protected] wrote:

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.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/18a88fae-20be-448a-9022-d4f474bb13a1%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Cool, I’ll open an issue.

Is there a way to deselect all selections after the BoxSelectTool is used? All I really need is to grab the indices from the selection but I don’t want the plot to visually change.

I’ve seen the .nonselection_glyph attribute but it doesn’t seem to do the trick.

···

On Thursday, March 16, 2017 at 10:39:06 AM UTC-4, Bryan Van de ven wrote:

Hi,

Line glyphs currently only support hit testing by point and by span. There’s not some huge technical hurdle, but it’s never be exactly clear to me what the right policy for hit testing lines against rects should be. Is it sufficient to have any part of a line in the box? Or does all of a line have to be contained? I don’t see an issue for this so I’d suggest opening one on GH and discussing your use case so that maybe we can hash out what the right behavior is.

Thanks,

Bryan

On Mar 16, 2017, at 09:27, [email protected] wrote:

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.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/18a88fae-20be-448a-9022-d4f474bb13a1%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.