0

我使用 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)

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

在此处输入图像描述

4

1 回答 1

0

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

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

于 2021-07-22T07:56:24.880 回答