为了账号安全,请及时绑定邮箱和手机立即绑定

散景:显示/隐藏数字的小工具

散景:显示/隐藏数字的小工具

喵喵时光机 2021-06-18 18:39:27
希望按照 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 和他们为这个解决方案奠定基础的答案。


查看完整回答
反对 回复 2021-06-22
  • 2 回答
  • 0 关注
  • 97 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号