Control the Bokeh xwheel_zoom tool using a Bokeh widget/callback

I am using xwheel_zoom (WheelZoomTool) for a Bokeh chart with datetime axis.

p = figure(x_axis_type="datetime", tools='xwheel_zoom, crosshair, undo, reset')

I provide pandas TimeStamp as the x value of this chart. For example: pd.Timestamp.now(tz='utc') .
Using xwheel_zoom, I could zoom in to see my chart better for a given time (e.g. last hour).

Is there any way in Bokeh I could achieve this zoom functionality by coding or connecting to the xwheel_zoom and controling it with a Bokeh widget (e.g. Bokeh dropdown)?

My objective is to have a button to click on and let it show me the zoomed in x_axis for the last hour, or show the chart between a datetime period I define. Ideally, I do not want to re-define/re-draw the chart again and just want to control the xwheel_zoom functionality.

There’s not any direct way to manipulate the zoom tool. But you can set the range start/end in a CustomJS callback (which seems much simpler in any case). There’s lots of information and examples about CustomJS callbacks in the Users’ Guide:

https://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html

1 Like

If you cross-post, please also include the links to the questions on other websites. https://stackoverflow.com/q/62075001/564509

1 Like

sure; thanks