2017-12-26 38 views
1

ipywidget 탭에 상호 작용 기능을 표시하려고합니다. 아래 코드는이 작업을 시도한 것이지만 드롭 다운 목록 만 보았지만 플롯은 표시되지 않았습니다. 또한 interaction() 함수를 별도로 포함하여 탭에서 작동하는 방식을 보여줍니다. 이것에 대한 도움은 많이 감사합니다. 고맙습니다.ipywidgets의 탭에 interact()를 표시하는 방법 Python

from ipywidgets import * 
import seaborn.apionly as sns 
df = sns.load_dataset('iris') 

#plot 
def plot_image(x): 

    data = df 

    if x != 'Select': 
     xplot = data[x] 
     sns.distplot(xplot) 
     plt.show() 

#define widgets 
x = widgets.Dropdown(
     options=df_cols, 
     value=df_cols[0], 
     description='X' 
    ) 

x.set_title = 'x' 

#assign widgets to tabs 
tab_visualise = widgets.HBox([x]) 

#create tabs 
tab_nest = widgets.Tab() 
tab_nest.children = [tab_visualise] 
tab_nest.set_title(0, 'Visualise') 
tab_nest 

#interact function in isolation 
interact(plot_image, x = x) 

답변

1

대신 대화식을 사용해보십시오. 이것은 당신이 완벽하게 작동

from ipywidgets import * 
import seaborn.apionly as sns 
df = sns.load_dataset('iris') 
import matplotlib.pyplot as plt 

#plot 
def plot_image(x): 

    data = df 

    if x != 'Select': 
     xplot = data[x] 
     sns.distplot(xplot) 
     plt.show() 

#define widgets 
x = widgets.Dropdown(
     options=df.columns, 
     value=df.columns[0], 
     description='X' 
    ) 

x.set_title = 'x' 

#assign widgets to tabs 
tab_visualise = widgets.HBox([x]) 

#create tabs 
tab_nest = widgets.Tab() 
# tab_nest.children = [tab_visualise] 
tab_nest.set_title(0, 'Visualise') 


#interact function in isolation 
f = interactive(plot_image, x = x); 
tab_nest.children = [VBox(children = f.children)] 
display(tab_nest) 

enter image description here

+1

당신의 tab_list에 자식으로 중 VBOX에 결합하고 추가 할 수 있습니다 입력 및 출력 위젯을 반환합니다. 당신의 훌륭한 도움에 감사드립니다. – user3550647