How to reset figure directly from python code (like the ResetTool button)?

I discover Bokeh one month ago, Wonderful! Except one thing that I cannot solve :
I’d like to reset all my plots simultaneously with exactly the same way than the “ResetTool” button.
So i need one intruction able to copycat it for each figure…
I saw on internet something like : myfigure.reset.emit() but doesn’t work
any ideas ?

PS : short video of my project there : yt_video

There is not an especially good way to reset plots programmatically present. You would need to call the reset method on the plot view (that is what the reset tool does). Bt view objects are not as easily accessible. There is a window global Bokeh.index that holds all view objects, you will just have to root around that object to find the views that you want to call reset on.

Also, just in case it’s not evident: the above discussion regards JavaScript. There is no direct way to do this from Python, you would need to trigger a JS callback or CustomAction to do what is described above.

Also! That video and project look amazing! Please consider writing up something short about it (with some images ideally) in our Showcase

I’ll try to look around JS callback / CustomAction but it seems quite complicated.
Bytheway if s.o. already success to do it, let me know :slight_smile:

P.S.: showcase, why not when it will be finish :wink:

New version : youtube

Anyone for the famous ‘reset’ function :sleepy:

from bokeh.layouts import row
from bokeh.models import Button, CustomJS
from bokeh.plotting import figure, show

p1 = figure()[1, 2, 3, 4, 5], [2, 5, 8, 2, 7])
p2 = figure()[2, 5, 8, 2, 7], [1, 2, 3, 4, 5])

b = Button(label="Reset all plots")
document.querySelectorAll('.bk-tool-icon-reset[title="Reset"]').forEach(d =>

show(row(p1, p2, b))

One thing to note - I didn’t use Bokeh.index because it requires traversing the whole tree structure when layouts have any level of nesting (rows, columns, grids).
The method in the code block just finds the HTML elements that represent the reset buttons and clicks on them. So it will work only if there is such a button on a plot. Also, the code will break if something relevant changes in Bokeh (a different class name or a different tool name or not using the title attribute). But since the BokehJS API is not yet considered stable, the same can happen with Bokeh.index or any other method.

Thousand of time thank you !!!
It works :slight_smile: