【问题标题】:How to autohide the Bokeh toolbar when using holoviews使用全息视图时如何自动隐藏散景工具栏
【发布时间】:2019-11-30 03:12:47
【问题描述】:

holoviews 文档提到可以隐藏或移动 Bokeh 工具栏:http://holoviews.org/user_guide/Plotting_with_Bokeh.html 散景文档展示了如何自动隐藏工具栏,使其仅在鼠标悬停时显示。

是否可以在使用全息视图时自动隐藏工具栏,因为它不允许我传递像 toolbar='autohide' 这样的选项

欢迎任何帮助。

fundYear.hvplot.bar(
    x='year',
    y='fundingReq',
    rot=90,
).opts(
    toolbar='left',
    title="Funding Requested per Year",
    yformatter='$%f',
)

【问题讨论】:

  • 请注意,Bokeh 目前不支持从多图布局中隐藏工具栏,因此任何基于 HoloViews 的解决方案都将仅限于单图。

标签: python bokeh holoviews hvplot


【解决方案1】:

工具栏位置的可能设置有:

['above', 'below', 'left', 'right', 'disable', None]

所以你不能这样设置自动隐藏,但是...

1) 您可以使用hooks 设置自动隐藏。

使用钩子,您可以在绘图之前对其进行自定义。

def set_toolbar_autohide(plot, element):
    bokeh_plot = plot.state
    bokeh_plot.toolbar.autohide = True

your_plot.opts(hooks=[set_toolbar_autohide], backend='bokeh')

您还可以在常见问题解答中找到有关挂钩的有用信息:
https://holoviews.org/FAQ.html

2) 另一种解决方案是将您的 Holoviews 图转换为实际的散景图,然后将散景工具栏设置为自动隐藏:

快速解决方案基本上是:

my_bokeh_plot = hv.render(my_hv_plot, backend='bokeh')
my_bokeh_plot.toolbar.autohide = True

第二个解决方案的完整工作示例:

# import libraries
import numpy as np
import pandas as pd

import holoviews as hv
import hvplot.pandas
hv.extension('bokeh', logo=False)

from bokeh.plotting import show


# create sample dataframe
df = pd.DataFrame({
    'col1': np.random.normal(size=30),
    'col2': np.random.normal(size=30),
})

# create holoviews plot
my_hv_plot = df.hvplot.scatter(label='Scattering around', width=700)

# turn plot into bokeh plot
my_bokeh_plot = hv.render(my_hv_plot, backend='bokeh')

# set toolbar to autohide
my_bokeh_plot.toolbar.autohide = True

# show plot
show(my_bokeh_plot)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-06
    • 2019-03-21
    • 2021-07-26
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    相关资源
    最近更新 更多