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) 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?