"previously" drawn polygon should be deleted

Hi,
I draw polygon dynamically as related part of the code:

p1=p.add_glyph(source_patch, glyph)

draw_tool_p1 = PolyDrawTool(renderers=[p1])
p.add_tools(draw_tool_p1)

I want, when I draw one polygon , “previously” drawn polygon is deleted from the plot.
how can I do that?
regards

Edit tools work by updating a ColumnDataSouce that drives the glyph (in this case, a polygon). So you would update the plot the same way as with any other glyph, i.e. update the data stored in the data source.

Another way is to set num_objects of your PolyDrawTool to 1

See: tools — Bokeh 2.4.2 Documentation

1 Like

Thanks @kaprisonne I had forgotten that existed!

1 Like