Clear Figure

I am creating a guitar fretboard and is trying to write an clearFretboard. I am trying to find a way to remove everything from the figure. Thank you

It’s ok, I found another solution which is removing the figure from the layout and then readding it in to the layout

Just noting that that is actually the solution I was going to propose. But it does depend, e.g. if you want to “clear” but then only to re-draw the same set of glyphs, just with different data, then you could also empty of the columns of all the ColumnDataSources of the glyphs. Bokeh is very good at updating the data of existing glyphs (even if that update is empty arrays). But if you need some entirely different plot with entirely different glyphs, then yes, just make an entirely new plot.

1 Like

Thank you! I didn’t use ColumnDataSources. But use glyphs like just drawing it? like Line, Circle, etc. Is there a way to clear that? I was going for clear.

@anoSF There are always column data sources. If you don’t create them explicity, then Bokeh creates them for you behind the scenes. A CDS drives every glyph, and it is often times very useful to create the CDS yourself, e.g. so that you can update its .data mapping. There are helpful docs here:

There are lots of examples in the docs and in the GitHub repo of updating to some new value to change a plot.

1 Like

Also is there a way to speed up when deleting figure and redrawing? Also because another example is I delete the figure and need to redraw all circles, when drawing circles, it takes a while. Thank you

Updating the data, rather than deleting and re-creating the entire plot, is the way to speed things up. It also matters things like how much data are we talking about? I really should have asked for this earlier, but it’s basically impossible to speculate in detail without a complete Minimal Reproducible Example to focus the discussion.