Search code examples
python-3.xbokehholoviews

How to access bokeh (figure) parameters


I would like to change the default tools that holoviews gives after plotting something using bokeh as backend. From what I have read so far I can do this using Hooks but I haven't figure how. The instruction using bokeh should be something like this:

plot = figure(tools="pan,wheel_zoom,reset")

This is what I have but it doesn't work:

def hook_test(plot, element):
    plot.state.tools = ["pan,wheel_zoom,reset"]

hv.Curve([1, 2, 3]).opts(finalize_hooks=[hook_test])

Solution

  • You should be able to pass a list of tool names as strings or as tool object instances to the .opts method. One tricky aspect is that the list of tools only extends the default set, and if you want to replace it, you'll need to separately remove the default_tools:

    import holoviews as hv
    hv.extension('bokeh')
    hv.Curve([1, 2, 3]).opts(tools=['pan','wheel_zoom','reset'], default_tools=[])
    

    screenshot