☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Want elegant way to remove items from a plot

Community Supportbokeh
Aziuth
Aziuth

So, I have this big plot, containing lots of data. Over this plot, I am painting some arrows to showcase certain properties.

Now my program is interactive, and based on what actions the user takes, the arrows are to change. Since the plot contains a lot of data, I do not want to recreate it each time this happens. I just want the arrows to change.

For a lot of render objects in Bokeh, you can state a source, and with that source changing, the rendering changes. Something like that would be nice here, but this seems not to exist for arrows.

Therefore, what I have to do is for each new set of arrows, first delete the old set of arrows. And the code for that so far is ugly. So far, it works like this, with there being a class around all of this.

Important class members:
self.plot stores the actual plot
self.arrows stores the list of the current arrows

def update_arrows(self, data) -> None:
    self.clear_arrows()
    <do something with data>
    for <some iteration>:
        ...
        arrow = Arrow(...)
        self.plot.add_layout(arrow)
        self.arrows.append(arrow)

def clear_arrows(self) -> None:
        item_array = getattr(self.plot, "center")
        for arrow in self.arrows:
            item_array.remove(arrow)
        self.arrows = []

As one can see, in clear_arrows(), I am using a bit of black magic. I read into the source code of Bokeh, and found that with getattr, I can access the items within a plot. This doesn’t look like an official functionality that was made for the outside at all. But I haven’t found anything else which would work for me, say a fictional method plot.remove_layout(arrow).

Is there a more elegant way to do things here?

⌁   Link to post
Aziuth
Aziuth

No. They are somewhat stable in their amount, but can easily vary in the exact number.
Also they do have an upper bound (that isn’t too high).

You were probably thinking about reordering them?
Given my somewhat stable amount, I might be able to have some turning invisible, but that would feel kinda dirty to me.

⌁   Link to post
Bryan
Bryan

I don’t have any immediate suggestions, but I should state that the plan is for arrows to becomethe same as other “regular” glyphs (i.e. driven by a CDS that you can update), in the near-ish future.

⌁   Link to post

End of archived discussion · Replies are disabled