How to set active tools in Holoviews

强颜欢笑 提交于 2019-12-23 03:41:54

问题


Sometimes my plots get drawn with the pan tool active and sometimes they draw with pan and wheel_zoom active. I'd like to force wheel_zoom to be active upon rendering. Is there a way to do this?


回答1:


Since holoviews 1.11.0 was released the original answer has been outdated. HoloViews now has an explicit option to set the active tool(s), called active_tools which accepts a list of tool names or instances, e.g. to activate the wheel_zoom tool by default you would do this:

 hv.Curve([1, 2, 3]).options(active_tools=['wheel_zoom'])

The rest of the answer below is outdated:

For any options that are not directly exposed in HoloViews you can define hooks which can directly modify the bokeh models. Here is a simple example that defines a hook to set the active scroll tool (as described in the bokeh docs):

def set_active_tool(plot, element):
    plot.state.toolbar.active_scroll = plot.state.tools[2]

hv.Curve([1, 2, 3]).options(finalize_hooks=[set_active_tool])

Setting the active tool seems like a fairly common action though, so filing an issue to request that the active tools can be declared directly as a plot option would be appreciated.



来源:https://stackoverflow.com/questions/50415434/how-to-set-active-tools-in-holoviews

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