"previously" drawn polygon should be deleted

I draw polygon dynamically as related part of the code:

p1=p.add_glyph(source_patch, glyph)

draw_tool_p1 = PolyDrawTool(renderers=[p1])

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

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: bokeh.models.tools — Bokeh 2.3.2 Documentation

1 Like

Thanks @kaprisonne I had forgotten that existed!

1 Like