悬停工具 - 列名中带有空格的数据框在悬停时不起作用?

Hover tool - Dataframes with spaces in column names don't work in hover?

我注意到,如果我尝试在 Holoviews 图中使用悬停工具,工具提示中包含空格的列名将不起作用。在 Bokeh 中,只要在创建悬停对象时将列名称括在花括号中,就可以使用空格。但这在 Holoviews 中似乎不起作用。在下面的示例中,col2 和 col3 值在悬停工具提示中正确显示,但 col 1 显示为 ????

df = pd.DataFrame({'col 1': [1, 2, 3, 4, 5], 'col2': [2, 5, 8, 2, 7], 'col3': ['A', 'b', 'C', 'd', 'E']})
df

hover = HoverTool(tooltips=[
    ("index", "$index"),
    ("col 1", "@{col 1}{0.0}"),
    ("col2", "@col2"),
    ("col3", "@col3"),
])

bars = hv.Bars(df, kdims=["col 1"], vdims=['col2',col3']).opts(plot=dict(tools=[hover]))
bars

我是不是遗漏了什么,或者我是否必须重命名所有列名称以删除空格?

HoloViews 正在对其中包含空格的列进行内部转义。如果将列引用更改为 @{col_1},它应该可以工作:

hover = HoverTool(tooltips=[
    ("index", "$index"),
    ("col 1", "@{col_1}{0.0}"),
    ("col2", "@col2"),
    ("col3", "@col3"),
])

我正在将项目动态传递到分组的 vbar 图表。并且发现我不得不使用下面的解决方案......诚然有点 hacky

tooltips = []
for item in items:
    ...some code
    tooltips.append((item, '@{' + item + '}'))

hover = HoverTool(tooltips=tooltips)