python - CheckboxGroup、散景、堆积条形图
问题描述
我用悬停工具在散景中制作了一个堆积条形图,现在还想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
解决方案
You're using show
which creates a static HTML page. But to on_change
, you pass a Python function, and for that to work you need to use a Bokeh server. Try follow this example: https://docs.bokeh.org/en/latest/docs/user_guide/server.html#single-module-format
If it still doesn't work, make sure to post the complete code that can be run without any modifications.
推荐阅读
- vue.js - 单击复选框后,V-model 未更新
- console - 为什么输出以 asci 码而不是整数打印?dart
- c# - 协方差不适用于代表
- go - 编码 SNMP 消息并从代理读取响应
- tsql - 如何在 Visual Studio 2017 中更改 Transact-SQL 代码的自动格式?
- javascript - 将一组 JSON 对象从 Google 表格传递到 HTML 服务
- php - 更新购物车 Laravel
- c# - 使用 SSIS 从 Sharepoint 中提取 JSON 并导入 Oracle
- mongodb-query - 带有不存在索引名称的 pymongo 光标提示:“规划器返回错误:错误提示”
- java - ProgressMonitor 的 JavaFX 等效项