根据单选按钮的值执行操作,并在Bokeh中单击按钮上的复选框

时间:2019-06-17 12:14:03

标签: python bokeh

需要生成一个基于单选图的值,该值是从单选按钮和复选框中选择的。

  • 单选按钮1(RB1):温度,湿度,压力。
  • 单选按钮2(RB2):24小时,48小时。
  • 复选框(CB1):印度,英国,意大利。

我应该能够从RB1,RB2,CB3(分别为温度,24小时,印度)中进行选择,并基于这些值,需要生成相应的图作为输出。 用类似的示例在Python的Bokeh中进行的插图将大有帮助。

我一次只能基于RB1或RB2或CB1的一个输入来做出反应或采取行动。无法同时基于所有值采取措施。

1 个答案:

答案 0 :(得分:0)

据我所知,您想要这种模式:

# Set up multiple widgets
offset = Slider(title="offset", value=0.0, start=-5.0, end=5.0, step=0.1)
amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0, step=0.1)
phase = Slider(title="phase", value=0.0, start=0.0, end=2*np.pi)
freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1, step=0.1)

# Set up one callback for all the widgets, that uses all their values
def update_data(attrname, old, new):

    # Get all the current slider values
    a = amplitude.value
    b = offset.value
    w = phase.value
    k = freq.value

    # Generate the new curve based on all the values
    x = np.linspace(0, 4*np.pi, N)
    y = a*np.sin(k*x + w) + b

    # This update uses values from all four sliders at the same time
    source.data = dict(x=x, y=y)

这里我用Slider进行了说明,但是该原理适用于所有小部件。