What's the command to “reset” a bokeh plot?

前端 未结 3 475
生来不讨喜
生来不讨喜 2021-01-04 07:46

I have a bokeh figure that has a reset button in the toolbar. Basically, I want to \"reset\" the figure when I update the data that I\'m plotting in the figure. How can I do

3条回答
  •  盖世英雄少女心
    2021-01-04 08:48

    I was struggling to make it work with Bokeh 2.2.1, but this JS p.reset.emit() does not seem to work.

    What worked for me was to manually set the Figure renderers attribute to an empty list inside a callback function, called via on_click(). This only works with a Bokeh server running, though:

    $ bokeh serve --show example.py
    

    example.py:

    from bokeh.layouts import column
    from bokeh.models import Button
    from bokeh.plotting import curdoc, figure
    
    p = figure(tools="reset,pan,wheel_zoom,lasso_select")
    p.circle(list(range(10)), list(range(10)))
    
    def clear_plot(attr):
        p.renderers = []
    
    b = Button(label="Clear plot")
    b.on_click(clear_plot)
    
    curdoc().add_root(column(p, b))
    

提交回复
热议问题