How to remove the ability to pan on drag mouse in a holoviews plot

When creating any plot by default it allows some manipulation of the image using the mouse for interactivity.

Unless specified otherwise and when using a bokeh backed, a toolbar appears on the image with many tools tht can be used to manipulate the image, like pan, zoom, etc.Look at the bokeh side bar in this image on the right:

Removing the toolbar is possible by using

plot.opts( toolbar=None)

However, even if the toolbar is removed a user can still drag the mouse over a plot with the button clicked and the plot image will move since the pan tool is still active, even if not accessible through the toolbar. So how can it be removed?

The solution here is by telling holoviews which tools the plot will support. Typically this is done by specifying tools from the set of tools bokeh support - see:

However, this is not sufficient in this case and we need to to remove capabilities that are provided by default. To do this we need to use the default_tools and if we want to remove the bokeh tool base we also need to remove the toolbar.
So the solution should be:

plot.opts( toolbar=None, default_tools = [])

Here is an example that creates a plot that cannot be dragged.

import holoviews
from holoviews import opts


def SaveFile(FileName, PlotObject, Format):
    'Save file using holoviews mechanism', FileName, fmt=Format)

data = [None]*20

for i in range(20):
    data[i] = {
        'Param': ['b','c', 'a'],
        'Value': [1+(i*0.1), 0+(i*0.2), 0.5+(i*0.3)],
        'alpha': [0.5, 1, 0.3],
        'color': ['red', 'blue', 'green'],
        'marker': ['circle', 'triangle', 'diamond'],
        'size': [5+i, 15+i, 40-i]

for i in range(10):
    BarDict[i] = holoviews.Bars(data[i], kdims=['Param'], vdims=['Value','color']).opts( color='color')
MapBarPlot = holoviews.HoloMap(BarDict,kdims=['Iter']).opts( toolbar=None, default_tools = []) 


1 Like