[英]How can I show one figure and one datatable on one tab if there is multiple datatables in bokeh?
I have four figure, on four tabs.我有四个数字,在四个选项卡上。 I also have four datatables, one for each datasource/figure.
我还有四个数据表,每个数据源/图形一个。
I want to show only one datatable in one tab.我只想在一个选项卡中显示一个数据表。
I tried to use column layout and but it is not iterable.我尝试使用列布局,但它不可迭代。
show( column( data_table4,Tabs(tabs=[tab4]) ), column( data_table3,Tabs(tabs=[tab3]) ) )
The trick is to use a layout
like row
, column
or grid
inside a TabPanel
.诀窍是在
TabPanel
中使用像row
、 column
或grid
这样的layout
。 Pass the layout
to the child argument.将
layout
传递给子参数。
from bokeh.models import TabPanel, Tabs, DataTable, ColumnDataSource, TableColumn
from bokeh.layouts import column
from bokeh.plotting import figure, show, output_notebook
output_notebook()
source = ColumnDataSource({
'x': [1, 2, 3, 4, 5],
'y1':[6, 7, 2, 4, 5],
'y2':[7, 3, 2, 3, 1],
})
p1 = figure(width=300, height=300)
p1.circle('x', 'y1', size=20, color="navy", alpha=0.5, source=source)
columns1 = [
TableColumn(field='x', title='x'),
TableColumn(field='y1', title='y1'),
]
data_table1 = DataTable(source=source, columns=columns1, width=300, height=300)
tab1 = TabPanel(child=column([p1, data_table1]), title="circle")
p2 = figure(width=300, height=300)
p2.line('x', 'y2', line_width=3, color="navy", alpha=0.5, source=source)
columns2 = [
TableColumn(field='x', title='x'),
TableColumn(field='y2', title='y2'),
]
data_table2 = DataTable(source=source, columns=columns2, width=300, height=300)
tab2 = TabPanel(child=column([p2, data_table2]), title="line")
show(Tabs(tabs=[tab1, tab2]))
Attention: In bokeh
older than 3.0.0 TabPanel
was named Panel
.注意:在早于 3.0.0 的
bokeh
中, TabPanel
被命名为Panel
。
The solution is base on the examples tab_panes and data.table_plot .该解决方案基于示例tab_panes和data.table_plot 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.