Best way to turn off zoom tool by default?

I find the zoom tool on plots very annoying, as whenever I am scrolling through notebooks, plots will hijack my zoom wheel and start moving plots around in funny ways, then I always have to hit the chart reset button and continue scrolling, being careful to be outside the chart.

I find the documentation on modifying tools to be hard to understand. Does anyone know the best way to turn zoom tool off by default for all hvplot charts?

Thanks!

1 Like

plot.opts(default_tools=["pan"])

1 Like

That’s a good remark, HoloViews has turned wheel_zoom by default recently (in Set pan and wheel_zoom as the default Bokeh active tools by maximlt · Pull Request #5480 · holoviz/holoviews · GitHub, followed-up by this fix Fix active_tools to only be set for enabled tools by Hoxbro · Pull Request #5616 · holoviz/holoviews · GitHub) as it seems like it is what you want in most cases when you create a single plot, for easier exploration. But indeed when you want to scroll through a page and that instead you end up zooming in by mistake on one or more plots, it’s not great UX!

I thought this would work, it didn’t:

import holoviews as hv

hv.opts.defaults(active_tools=['pan'])

So instead I tried updating the default of active_tools on ElementPlot, the base class of all the (bokeh here) Elements, and it worked:

import holoviews as hv

hv.plotting.bokeh.element.ElementPlot.active_tools = ['pan']  # or `['box_zoom'], or any tool that's not `['wheel_zoom']` :)

It’d certainly be worth looking into what’s the default of other interactive plotting libraries.

3 Likes

I’m actually very appreciative of the wheel zoom being on by default, as most of the interactive data inspection is about zooming in/out, rather than just panning around.

Maybe the middle-ground is to improve how one can customize the plotting defaults.

4 Likes

Is there some way that wheel zoom could be enabled, but only after the user deliberately clicks on the plot to somehow make it “active” or give it “focus” (not sure of the correct term)?

Update

It seems I can do this by specifying the active_tools:

opts.defaults(opts.Image(active_tools=['pan']))

# Or, more explicitly
opts.Image(
    default_tools=['save', 'pan', 'wheel_zoom', 'box_zoom', 'reset'],
    active_tools=['pan'],
)

Then the user can click on the wheel_zoom tool if they want. Still not sure how to do this globally but it gets me close. (It would still be nice if the tools could be activated only when the user clicks the image. Is something like this possible?)

It seems to be possible~

import xarray as xr
import hvplot.xarray
import holoviews as hv
from holoviews.streams import Tap

def plot_and_activate_tool(x, y):
    plot = (
        ds.isel(time=0)
        .hvplot.scatter("lon", "lat", color="air")
        .opts(active_tools=["pan"], title="Wheel zoom is not activated...")
    )
    
    # prior to tapping on the plot
    if x is None and y is None:
        return plot

    # after tapping on the plot
    return plot.opts(active_tools=["wheel_zoom"], title="Wheel zoom is now activated!")


ds = xr.tutorial.open_dataset("air_temperature")
plot = hv.DynamicMap(plot_and_activate_tool, streams=[Tap()])
plot

Initially

After tap