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

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

Add a method to "reset" a figure #5071

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

Comments

@swevrywhere
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.

http://stackoverflow.com/questions/39278110/whats-the-command-to-reset-a-bokeh-plot

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

I would like the same.

Looking for a way to easily clear a bokeh figure

@ross8711
Copy link

I also would need way of doing this.

@uweschmitt
Copy link

Would also need this.

@nanodan
Copy link

nanodan commented Oct 19, 2017

Also need this.

@pchavanne
Copy link

Would need this too.

@Milly
Copy link

Milly commented Dec 13, 2017

Need this.

@malewick
Copy link

Would also need this.

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

bryevdv commented Apr 5, 2018

After #7757 is merged, this will work:

from bokeh.io 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")
p.circle(list(range(10)), list(range(10)))

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

show(column(p, b))

@nathan-vignal
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 ?

@bryevdv
Copy link
Member

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

@RainerHeintzmann
Copy link

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

p.renderers[0].visible=False
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:

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

@CLocs
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
signal_plt_cds.data = {"xs": [], "ys": []}  # reset work-around
signal_plt_cds.data = {"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
Projects
None yet
Development

Successfully merging a pull request may close this issue.