【发布时间】:2020-07-29 09:11:07
【问题描述】:
我用悬停工具在散景中制作了堆积条形图,现在还想在绘图中添加CheckboxGroup。然而,我对 Bokeh 很陌生,所以我有点挣扎。我特别不确定如何制作更新功能,我试图启动它但根本不明白它需要做什么:
trees_to_plot = [tree_selection.labels[i] for i in
tree_selection.active]
temp = make_dataset(trees_to_plot,
bin_width = 40)
# \TODO: add more code here!
图表本身的代码如下所示:
p = figure(x_range = districtName,plot_width = 900, plot_height=400,
title='Tree pr. district',toolbar_location= None)
# Stacked bar chart
renderers = p.vbar_stack(stackers=treeName,x='bydelsnavn',source=temp,
width=0.5, color = colornames)
# Add the hover tool
for r in renderers:
tree = r.name
hover = HoverTool(tooltips=[
("%s" % tree, "@{%s}" % tree)
], renderers = [r])
p.add_tools(hover)
p.xaxis.axis_label = 'Copenhagen city cistricts'
p.yaxis.axis_label = 'Tree counts'
# Creat the checkbox selection element
tree_selection = CheckboxGroup(labels=treeName, active = [0,1])
# Link the checkboxes to the information on the graph
tree_selection.on_change('active', update)
# Add to the CheckboxGroup to the figure
controls = WidgetBox(tree_selection)
layout = row(controls,p)
show(layout)
此代码将显示所有带有图表的复选框,但这些复选框和图表本身之间显然没有发生任何交互。有人能指出我正确的方向吗?
提前致谢! :D
【问题讨论】:
标签: python bokeh stacked-chart user-interaction