希望按照 UI 的方式做一些事情,如下所示:Bokeh:使用復選框小部件隱藏和顯示繪圖,其中我可以選擇性地在一列圖形中顯示/隱藏整個圖形。我可以選擇顯示哪些圖(假設我可以命名數字)的下拉菜單(帶有多個選擇的 OptionMenu)會更可取。我對JS不熟悉,有什么指導嗎?(提前致謝)我希望圖像不再可見,下一個圖形會像這樣跳起來:例如:我在生成為的列中有多個數字:from bokeh.io import output_file, showfrom bokeh.layouts import columnfrom bokeh.plotting import figureoutput_file("layout.html")x = list(range(11))y0 = xy1 = [10 - i for i in x]y2 = [abs(i - 5) for i in x]# create a new plots1 = figure(plot_width=250, plot_height=250, title=None)s1.circle(x, y0, size=10, color="navy", alpha=0.5)# create another ones2 = figure(plot_width=250, plot_height=250, title=None)s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)# create and anothers3 = figure(plot_width=250, plot_height=250, title=None)s3.square(x, y2, size=10, color="olive", alpha=0.5)# put the results in a column and showshow(column(s1, s2, s3))
2 回答

交互式愛情
TA貢獻1712條經驗 獲得超3個贊
s1.tags, s2.tags, s3.tags = ['Foo'], ['Bar'], ['Arr'] # name your plots
plots = [s1, s2, s3]
labels = [(plots[i].tags[0]) for i in range(len(plots))]
active = list(range(0, len(plots)))
chkbx = CheckboxButtonGroup(labels=labels, active=active)
callback = CustomJS(args=dict(plots=plots, chkbx=chkbx), code="""
for (let i = 0; i < plots.length; i++){
plots[i].visible = chkbx.active.includes(i)
}
""")
chkbx.js_on_click(callback)
show(column([chkbx] + plots))
感謝@bigreddot 和他們為這個解決方案奠定基礎的答案。
添加回答
舉報
0/150
提交
取消