如何在Bokeh中創(chuàng)建多頁布局的應(yīng)用

小樊
86
2024-05-20 11:16:24
欄目: 編程語言

在Bokeh中創(chuàng)建多頁布局的應(yīng)用可以通過使用 bokeh.models.widgets.Panelbokeh.models.widgets.Tabs 實(shí)現(xiàn)。以下是一個(gè)簡(jiǎn)單的例子:

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

# 創(chuàng)建多個(gè)圖表
plot1 = figure()
plot1.circle([1, 2, 3], [4, 5, 6])

plot2 = figure()
plot2.line([1, 2, 3], [4, 5, 6])

plot3 = figure()
plot3.triangle([1, 2, 3], [4, 5, 6])

# 創(chuàng)建面板
tab1 = Panel(child=plot1, title="Plot 1")
tab2 = Panel(child=plot2, title="Plot 2")
tab3 = Panel(child=plot3, title="Plot 3")

# 創(chuàng)建標(biāo)簽頁
tabs = Tabs(tabs=[tab1, tab2, tab3])

# 將標(biāo)簽頁添加到文檔
curdoc().add_root(tabs)

在這個(gè)例子中,我們首先創(chuàng)建了三個(gè)不同的圖表 plot1, plot2plot3,然后將它們分別放在面板中 tab1, tab2tab3。最后,我們創(chuàng)建一個(gè)標(biāo)簽頁 tabs,將這些面板添加到標(biāo)簽頁中,并將標(biāo)簽頁添加到文檔中。

當(dāng)你運(yùn)行這段代碼時(shí),你將看到一個(gè)包含三個(gè)標(biāo)簽頁的應(yīng)用程序,每個(gè)標(biāo)簽頁都包含一個(gè)不同的圖表。

0