You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Holoviews中实现Bokeh工具栏自动隐藏?

实现Holoviews+Bokeh工具栏自动隐藏的方法

Absolutely! You can definitely get that auto-hiding toolbar working with Holoviews and Bokeh. Even though you can't pass a toolbar='autohide' parameter directly to Holoviews' opts(), we can tap into the underlying Bokeh objects to make this happen. Here's the straightforward solution:

方法1:使用Holoviews的Hook函数(推荐)

Holoviews provides hooks—small functions that let you modify the underlying Bokeh plot object during rendering. We can use this to enable the toolbar's autohide feature:

First, define a hook function that enables autohiding:

def enable_autohide_toolbar(plot, element):
    # Access the Bokeh toolbar and set autohide to True
    plot.toolbar.autohide = True

Then, add this hook to your plot's opts():

fundYear.hvplot.bar(x='year', y='fundingReq', rot=90)\
    .opts(
        toolbar='left',
        title="Funding Requested per Year",
        yformatter='$%f',
        hooks=[enable_autohide_toolbar]  # Add the hook here
    )

方法2:直接修改渲染后的Bokeh对象

If you prefer to handle things after rendering the Holoviews plot, you can convert it to a Bokeh object and tweak the toolbar directly:

# Create your Holoviews plot as usual
hv_plot = fundYear.hvplot.bar(x='year', y='fundingReq', rot=90)\
    .opts(
        toolbar='left',
        title="Funding Requested per Year",
        yformatter='$%f'
    )

# Convert to a Bokeh plot object
bokeh_plot = hv.render(hv_plot)

# Enable autohide on the toolbar
bokeh_plot.toolbar.autohide = True

# Now you can display bokeh_plot however you normally would

Either approach will make the toolbar automatically hide and only show up when you hover over the plot area—exactly what you're looking for. This works because Holoviews is built on top of Bokeh, so we can always reach down to the underlying Bokeh components when we need fine-grained control like this.

内容的提问来源于stack exchange,提问作者Brian Mc Donald

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:46:33