猿问

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

希望按照 UI 的方式做一些事情,如下所示:Bokeh:使用复选框小部件隐藏和显示绘图,其中我可以选择性地在一列图形中显示/隐藏整个图形。我可以选择显示哪些图(假设我可以命名数字)的下拉菜单(带有多个选择的 OptionMenu)会更可取。

我对JS不熟悉,有什么指导吗?(提前致谢)

我希望图像不再可见,下一个图形会像这样跳起来:

例如:

我在生成为的列中有多个数字:


from bokeh.io import output_file, show

from bokeh.layouts import column

from bokeh.plotting import figure


output_file("layout.html")


x = list(range(11))

y0 = x

y1 = [10 - i for i in x]

y2 = [abs(i - 5) for i in x]


# create a new plot

s1 = figure(plot_width=250, plot_height=250, title=None)

s1.circle(x, y0, size=10, color="navy", alpha=0.5)


# create another one

s2 = figure(plot_width=250, plot_height=250, title=None)

s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)


# create and another

s3 = 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 show

show(column(s1, s2, s3))


喵喵时光机
浏览 98回答 2
2回答

交互式爱情

s1.tags, s2.tags, s3.tags = ['Foo'], ['Bar'], ['Arr'] # name your plotsplots = [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="""&nbsp; &nbsp; for (let i = 0; i < plots.length; i++){&nbsp; &nbsp; &nbsp; &nbsp; plots[i].visible = chkbx.active.includes(i)&nbsp; &nbsp; }&nbsp; &nbsp; """)chkbx.js_on_click(callback)show(column([chkbx] + plots))感谢@bigreddot 和他们为这个解决方案奠定基础的答案。
随时随地看视频慕课网APP

相关分类

Python
我要回答