Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to "reset" a figure #5071

swevrywhere opened this issue Sep 1, 2016 · 12 comments · Fixed by #7757

Add a method to "reset" a figure #5071

swevrywhere opened this issue Sep 1, 2016 · 12 comments · Fixed by #7757


Copy link

I want the ability to reset a figure via code in the same way as the figure reset tool.

I asked a related question on Stack Overflow, and it was recommended that I open an issue to track the request.

@birdsarah birdsarah added this to the short-term milestone Sep 2, 2016
Copy link

I would like the same.

Looking for a way to easily clear a bokeh figure

Copy link

I also would need way of doing this.

Copy link

Would also need this.

Copy link

nanodan commented Oct 19, 2017

Also need this.

Copy link

Would need this too.

Copy link

Milly commented Dec 13, 2017

Need this.

Copy link

Would also need this.

@bryevdv bryevdv modified the milestones: 0.12.x, 0.12.16 Mar 17, 2018
Copy link

bryevdv commented Apr 5, 2018

After #7757 is merged, this will work:

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

p = figure(tools="reset,pan,wheel_zoom,lasso_select"), list(range(10)))

b = Button()
b.js_on_click(CustomJS(args=dict(p=p), code="""

show(column(p, b))

Copy link

nathan-vignal commented May 9, 2019

the code given by bryevdv doesn't work, i get this js error "
Uncaught TypeError: Cannot read property 'emit' of undefined at eval (eval at <anonymous> (bokeh-0.12.7.min.js:25), <anonymous>:4:13) at r.execute (bokeh-0.12.7.min.js:25) at e.<anonymous> (bokeh-0.12.7.min.js:22) at t.emit (bokeh-0.12.7.min.js:2) at e.t._setv (bokeh-0.12.7.min.js:1) at e.t.setv (bokeh-0.12.7.min.js:1) at e.set (bokeh-0.12.7.min.js:1) at e.change_input (bokeh-widgets-0.12.7.min.js:1) at e._button_click (bokeh-widgets-0.12.7.min.js:1) at HTMLButtonElement.<anonymous> (bokeh-widgets-0.12.7.min.js:1)
Any idea on how i can reset a figure ?

Copy link

bryevdv commented May 9, 2019

@nathan-vignal it's the opposite, your version of Bokeh is way too old. This feature landed in 0.12.16 and your output shows 0.12.7

Copy link

If you are in a notebook, the simple solution can be to directly access the renderers in the figure p:

hides a specific renderer in the figure, whereas

p.renderers = []
would clear all the renderers. Of course you may need to force update of the display. In a notebook by calling:

I am not sure, how much of a hack this is, but it seems to work.

Copy link

CLocs commented Jun 7, 2022

If plotting using ColumnDataSource, one Python-only work-around is to reset the data. Here is a snippet example for a multi-line plot.

# Make initial plot
signal_plt_cds = ColumnDataSource(data={"xs": [[0,1,2], [0,1,2]], "ys": [[1,2,3], [4,5,6]]})
feature_plt = figure(background_fill_color="#fafafa")
_ = feature_plt.multi_line("xs", "ys", source=feature_plt_cds)

# Reset plot then update = {"xs": [], "ys": []}  # reset work-around = {"xs": [[0,1,2], [0,1,2]], "ys": [[10,20,30], [40,50,60]]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging a pull request may close this issue.