如何将小部件放入选项卡以控制选项卡中的图

时间:2019-05-11 04:37:39

标签: python widget bokeh

我正在尝试在选项卡中组织小部件和绘图。下面的代码和屏幕截图是我得到的。我需要将小部件select4tab1放在tab1中以控制plot1和plot2;将小部件select4tab2放在tab2中以控制plot3和plot4。

有人可以帮我吗? 谢谢 enter image description here

from ipywidgets import interact, interact_manual

import pandas as pd
import numpy as np

from bokeh.io import show, output_notebook, push_notebook
from bokeh.plotting import figure
from bokeh.layouts import gridplot
from bokeh.layouts import row, column, layout
from bokeh.models import CategoricalColorMapper, HoverTool, ColumnDataSource, Panel,FactorRange,LabelSet
from bokeh.models.widgets import CheckboxGroup, Slider, RangeSlider, Tabs,TableColumn, DataTable


output_notebook()


data=[['a',1,6],['a',2,6],['a1',1,3],['a1',2,8],['b',1,11],['b',2,3],['b1',1,21],['b1',2,4]]
df1=pd.DataFrame(data,columns=['group','time','rate'])
df2=df1

@interact
def plot(select4tab1=['a','a1','b','b1'],
         select4tab2=['a','a1','b','b1']):

    data4tab1=df1.loc[(df1.group==select4tab1) ]
    p1=figure(plot_width=400, plot_height=300)
    p1.line(data4tab1.time, data4tab1.rate)

    p2=figure(plot_width=400, plot_height=300)
    p2.circle(data4tab1.time, data4tab1.rate)

    data4tab2=df2.loc[(df2.group==select4tab2) ]
    p3=figure(plot_width=400, plot_height=300)
    p3.line(data4tab2.time, data4tab2.rate,color='red')

    p4=figure(plot_width=400, plot_height=300)
    p4.circle(data4tab2.time, data4tab2.rate,color='red')


    grid1=layout([[p1,p2]])
    tab1=Panel(child=grid1,title='tab1') 


    grid2=layout([[p3,p4]])
    tab2 = Panel(child = grid2, title = 'tab2')



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

1 个答案:

答案 0 :(得分:0)

这可能是不可能的,因为Bokeh小部件和ipywidgets通常不能一起工作或完全集成。要实现所需的功能,您应该使用Bokeh Select小部件和embed everything as a Bokeh server app in the notebook。我怀疑还有其他解决方案。