如何在Bokeh中启用交互式CheckboxGroup?

2024-09-28 23:03:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我在博克制作了一个散点图。我想创建两个矩形着色区域,当我选中复选框组中的两个复选框之一时显示。我正在使用.on_click回调来尝试此操作。这是我的代码:

 source = ColumnDataSource(data = dict(x,y))
 hover = HoverTool(tooltips=["(indep,dep)","($x,$y)"])

 p = figure(plot_width = 300, plot_height = 300, tools = [hover], title = "sample")

 checkbox_group = CheckboxGroup(labels = ["select 1","select 2"])

 def clicker():
    if checkbox_group.active[0]:
        p.quad(top = 50.0,bottom = 25.0, left = 0.0, right = 25.0)
    if checkbox_group.active[1]:
        p.quad(top = 25.0,bottom = 0.0, left = 25.0, right =50.0)

 checkbox_group.on_click(clicker)

 circles = p.circle('x','y',source=source)
 hover.renderers.append(circles)

 output_file("test_scatter.html",mode="inline",title="sample scatter")

 L = layout([p],[widgetbox(checkbox_group)], sizing_mode = 'fixed')

 show(L)

输出显示散点图和两个复选框(均已禁用)。当我选中其中一个框时,着色区域不会出现。我做错什么了?在


Tags: sample区域sourceifplottitleongroup