Search code examples
pythonholoviewshvplotholoviz

Set box zoom (or pan or wheel zoom) as default in using Holoviews or Hvplot


My hvplot has default pan and wheel zoom as way of zooming and moving the graph.
But I want box zoom to be the default in my graph.
How do I do this in hvplot or holoviews?

import numpy as np
import pandas as pd
import holoviews as hv
import hvplot
import hvplot.pandas

df = pd.DataFrame(data=np.random.normal(size=[50, 2]), columns=['a', 'b'])
df_plot = df.hvplot.scatter(x='a', y='b')

hvplot pan is default active tool


Solution

  • The default setting can be changed to the one you need by adding .opts(active_tools=['box_zoom']) if you need box zoom.

    So add the following to your code:

    df_plot.opts(active_tools=['box_zoom'])
    

    In the same way you can choose to set 'pan' or 'wheel_zoom' as the active tools.

    For holoviews the answer would be very similar, for example:

    hv.Scatter(df).opts(active_tools=['box_zoom'])
    

    box_zoom is now set as active tool