How to control (active) tools in holoviews with bokeh backend

梦想与她 提交于 2020-07-10 01:06:23

问题


How do I control which tools are used / active in a holoviews plot with the bokeh backend? I've seen this SO answer, but that only adds a new active tool; it doesn't keep any other tools (e.g. pan) from being active.

For a specific example, suppose I only want the hover tool. I would try doing this:

import holoviews as hv
hv.extension("bokeh")
hv.Curve([1, 2, 3]).opts(tools=["hover"])

but then I end up with a plot that has hover in addition to the default tools. How do I specify the list of all tools that I want to use, so that no tools are used that aren't in that list?

Similarly, how do I specify the list of all active tools? E.g.

import holoviews as hv
hv.extension("bokeh")
hv.Curve([1, 2, 3]).opts(tools=["hover"], active_tools=[])

gives me both pan and hover being active; I want hover to be the only tool but no tool to be active.


回答1:


For your first question, use default_tools option:

hv.Curve([1, 2, 3]).opts(tools=["hover"], default_tools=[])

fot the second question, there is not method in holoviews to do this, but you can set it to the Figure object directly:

def set_tools(plot, element):
    plot.state.toolbar.active_drag = None

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



回答2:


For completeness, at the moment the following tools are possible:

box_edit, box_select, box_zoom, click, crosshair, help, hover, lasso_select, pan, point_draw, poly_draw, poly_edit, poly_select, previewsave, redo, reset, save, tap, undo, wheel_zoom, xbox_select, xbox_zoom, xpan, xwheel_pan, xwheel_zoom, xzoom_in, xzoom_out, ybox_select, ybox_zoom, ypan, ywheel_pan, ywheel_zoom, yzoom_in, yzoom_out, zoom_in, zoom_out

You can get a list of all possible options by just typing a non-existing one. The informative error message will give you a list of options to choose from. So just do:

hv.Scatter(df).opts(tools=['nonsense'])


来源:https://stackoverflow.com/questions/56992160/how-to-control-active-tools-in-holoviews-with-bokeh-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!