将布局添加到bokeh仪表板上的选项卡 [英] adding layout to tabs on bokeh dashboard

查看:151
本文介绍了将布局添加到bokeh仪表板上的选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在探索bokeh库. 我试图使用VBox将多个图添加到每个选项卡,但是没有用. 我在某处阅读了标签和& VBox/HBox不能一起使用.
那我该如何处理选项卡上的布局呢?

I'm exploring the bokeh library. I tried to add several plots to each tab using VBox, but it did not work. I read somewhere that tabs & VBox/HBox cannot be used together.
How do I handle the layout on the tabs then?

修改后的示例,每个标签添加几个元素:

Modified example to add several elements per tab:

from bokeh.models.widgets import Panel, Tabs
from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.models.widgets.layouts import VBox
output_file("slider.html")
p1 = figure(plot_width=300, plot_height=300)
p1.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)

p2 = figure(plot_width=300, plot_height=300)
p2.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=3, color="navy", alpha=0.5)
p=VBox(p1,p2)
tab1 = Panel(child=p,title="circle")
tab2 = Panel(child=p2, title="line")
tabs = Tabs(tabs=[ tab1, tab2 ])
show(tabs)

网站示例:

from bokeh.models.widgets import Panel, Tabs
from bokeh.io import output_file, show
from bokeh.plotting import figure

output_file("slider.html")

p1 = figure(plot_width=300, plot_height=300)
p1.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
tab1 = Panel(child=p1, title="circle")

p2 = figure(plot_width=300, plot_height=300)
p2.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=3, color="navy", alpha=0.5)
tab2 = Panel(child=p2, title="line")

tabs = Tabs(tabs=[ tab1, tab2 ])

show(tabs)

推荐答案

我不确定将HBox和VBox与Tabs一起使用,但是您可以使用layout在Tabs中排列内容,这对我和我认为比其他选项灵活一些.这是我认为可行的简单示例:

I'm not sure about using HBox and VBox with Tabs, but you can use layout to arrange things in tabs, it has worked well for me and I think is a bit more flexible than the other options. Here's a quick example I think works:

from bokeh.layouts import layout
from bokeh.models.widgets import Tabs, Panel
from bokeh.io import curdoc
from bokeh.plotting import figure

fig1 = figure()
fig1.circle([0,1,2],[1,3,2])
fig2 = figure()
fig2.circle([0,0,2],[4,-1,1])
fig3 = figure()
fig3.circle([0,4,3],[1,2,0])

l1 = layout([[fig1, fig2]], sizing_mode='fixed')
l2 = layout([[fig3]],sizing_mode='fixed')

tab1 = Panel(child=l1,title="This is Tab 1")
tab2 = Panel(child=l2,title="This is Tab 2")
tabs = Tabs(tabs=[ tab1, tab2 ])

curdoc().add_root(tabs)

我发现电影示例对于各种东西都非常有用,其代码为

I found the movies example very useful for all sorts of stuff, the code for which is here, and well worth a look.

这篇关于将布局添加到bokeh仪表板上的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆