Holoviews 中的水平滚动条

Horizontal scroll bar in Holoviews

我已经使用 Holoviews 进行了交互式可视化,并希望在图的底部有一个水平滚动条。我目前使用的滑块可以控制图中的列数,但我更喜欢水平滚动条。因此,通过增加行业数量,图的宽度和列的宽度不会改变。 这是我的代码和情节:

import pandas as pd
import panel as pn
import panel.widgets as pnw
import holoviews as hv
from bokeh.plotting import figure
hv.extension('bokeh')

from bokeh.models import HoverTool, BoxZoomTool, ResetTool, PanTool, WheelZoomTool, SaveTool, LassoSelectTool

data = df 
Options = ["All"] + list(data['country_code'].unique())
xlist = list(data['Industry'].unique())
Countries = pn.widgets.Select(name = "Country", options = Options, value = "All")
x = pn.widgets.IntSlider(name = 'Industry', value = 10, start = 10, end = 30)


hover = HoverTool(description='Custom Tooltip', tooltips = [('Industry', '@Title'),('Count', '@Count')])

@pn.depends(Countries.param.value, x.param.value)

def fig(Countries,x):
   
    opts = dict(title = "Companies by Industry", width = 50*x, height = 300, line_color = 'black' ,
                 tools = [hover], apply_ranges = True)




# Determine which country has been selected

    if Countries == "All":
        selected = data.groupby(['Industry']).sum().reset_index().rename(columns = {0:'Count'}).sort_values(by ='Count', ascending = False )[:x]
    
    else:
        selected = data[data['country_code'] == Countries].sort_values(by ='Count', ascending = False )[:x]
    
    selected['Title'] = 'title'


    return hv.Bars(selected, 'Industry', 'Count').opts(**opts)

widgets = pn.WidgetBox(Countries, x)
pn.Column(widgets, fig)

另外一点,我想向悬停工具添加另一个变量(此处称为标题),但它显示在所有列中,如 ???。我不知道为什么这些值没有正确传递到悬停工具。

可以在这里找到解决方案: https://discourse.holoviz.org/t/horizontal-scroll-in-holoviews/2516

只需要将最后一行更改为 pn.Column(widgets, pn.Column(fig, scroll=True, width=500))