Problems removing glyphs from figure when box select tool is used

I try to do the following (this task is rather contrived because it is invented solely for the purpose of isolating the problem): in a figure with box select tool, I plot a random point. Then I generate another random point, remove the old point in the figure, and plot the new random point. To remove the old point, I use the select method of figure to find the point, and then use the remove method of figure.renderers list. Please refer to the following MWE:

from bokeh.plotting import figure
from bokeh.layouts import layout
from bokeh.plotting import curdoc
from bokeh.models import Button, Range1d
from random import uniform

def on_lick(*args):
    old_point = fig.select(name="random_point")
    if len(old_point)>0:
        fig.renderers.remove(old_point[0])

    print(old_point)

    fig.circle(x=uniform(-1,1), y=uniform(-1,1), name="random_point")

fig = figure(tools="box_select")
fig.x_range = Range1d(-1, 1)
fig.y_range = Range1d(-1, 1)

btn = Button(label="generate a random point")
btn.on_click(on_lick)

curdoc().add_root(
    layout([[fig,btn]])
)

``

I ran the code in Bokeh server mode. When I pressed the point-generating button for several times, I noticed that fig.renderers.remove did not remove the old point at all; old points were piling up. However, if I didn’t use the box select tool when creating the figure, everything went fine. So I guess the inclusion of box select added additional references to the plotted glyphs, apart from fig.renderers.

How should I remove plotted points from figure with box select tool?

Left a response on the issue:

  https://github.com/bokeh/bokeh/issues/6423#issuecomment-307283106

(backwards... did not realize there was already an ML post)

Bryan

···

On Jun 8, 2017, at 04:40, Degang WU <[email protected]> wrote:

I try to do the following (this task is rather contrived because it is invented solely for the purpose of isolating the problem): in a figure with box select tool, I plot a random point. Then I generate another random point, remove the old point in the figure, and plot the new random point. To remove the old point, I use the select method of figure to find the point, and then use the remove method of figure.renderers list. Please refer to the following MWE:

from bokeh.plotting import figure
from bokeh.layouts import layout
from bokeh.plotting import curdoc
from bokeh.models import Button, Range1d
from random import uniform

def on_lick(*args):
    old_point = fig.select(name="random_point")
    if len(old_point)>0:
        fig.renderers.remove(old_point[0])

    print(old_point)

    fig.circle(x=uniform(-1,1), y=uniform(-1,1), name="random_point")

fig = figure(tools="box_select")
fig.x_range = Range1d(-1, 1)
fig.y_range = Range1d(-1, 1)

btn = Button(label="generate a random point")
btn.on_click(on_lick)

curdoc().add_root(
    layout([[fig,btn]])
)

I ran the code in Bokeh server mode. When I pressed the point-generating button for several times, I noticed that fig.renderers.remove did not remove the old point at all; old points were piling up. However, if I didn't use the box select tool when creating the figure, everything went fine. So I guess the inclusion of box select added additional references to the plotted glyphs, apart from fig.renderers.

How should I remove plotted points from figure with box select tool?

--
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/aa5e0426-ecfc-4327-8597-b408573e04c3%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.