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