简体   繁体   English

CheckboxGroup、散景、堆积条形图

[英]CheckboxGroup, bokeh, stacked bar chart

I have made a stacked bar chart in bokeh with a hover tool and now also wants to add a CheckboxGroup to the plot.我使用 hover 工具在散景中制作了堆叠条形图,现在还想将CheckboxGroup添加到 plot。 I am however very new to Bokeh, so I am struggeling a bit.然而,我对 Bokeh 很陌生,所以我有点挣扎。 I am especially unsure about how to make the update function, I have tried to start it but simply don't understand what it needs to do:我特别不确定如何进行更新 function,我试图启动它,但根本不明白它需要做什么:

    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!

The code for the chart itself looks like this:图表本身的代码如下所示:

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)

This code will show all the check boxes with the chart but no interaction is obviously happening between the boxes and the chart itself.此代码将显示所有带有图表的复选框,但框和图表本身之间显然没有发生任何交互。 Can someone point me towards to right direction?有人可以指出我正确的方向吗?

Thanks in advance: :D先谢谢了

You're using show which creates a static HTML page.您正在使用show创建一个 static HTML 页面。 But to on_change , you pass a Python function, and for that to work you need to use a Bokeh server.但是对于on_change ,您需要传递一个 Python function ,为此您需要使用 Bokeh 服务器。 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.尝试按照以下示例进行操作: https://docs.bokeh.org/en/latest/docs/user_guide/server.html#single-module-format如果它仍然不起作用,请确保发布完整的代码无需任何修改即可运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM