Bar
是旧的、已弃用的bokeh.charts
API 的一部分,该 API 已从核心 Bokeh 中完全删除。它仍然可以作为bkcharts
包使用,但它是完全无人维护和不受支持的。此时不应将其用于任何新工作。
然而,最近的工作使用稳定、受支持的bokeh.plotting
API 极大地改进了对条形图和其他分类图的支持。新的大型用户指南部分专门用于解释和演示多种简单和复杂的条形图。bokeh.plotting
此外,现在使用标准调用很容易制作条形图,悬停工具的一般指南和文档现在也适用。
您没有提供完整的最小示例,包括要运行的数据,因此我无法为您的用例提供具体建议。下面是一个使用 pandas 统计数据的简单条形图的完整示例(类似于将Bar
要执行的操作)以及使用“汽车”示例数据和bokeh.plotting
API 的悬停工具:
from bokeh.io import show, output_file
from bokeh.models import HoverTool
from bokeh.plotting import figure
from bokeh.sampledata.autompg import autompg as df
output_file("groupby.html")
df.cyl = df.cyl.astype(str)
group = df.groupby('cyl')
p = figure(plot_height=350, x_range=group, toolbar_location=None, tools="")
p.vbar(x='cyl', top='mpg_mean', width=0.9, source=group)
p.add_tools(HoverTool(tooltips=[("Avg MPG", "@mpg_mean")]))
show(p)
产生以下结果
