Jupyter小部件不显示

时间:2018-11-29 22:15:37

标签: widget jupyter-notebook

嗨,我有以下代码,当我执行它时,我看不到交互式小部件,请帮忙!附言执行代码,绘制图表,然后使用“ interact”函数返回值,但未显示交互式小部件。 令人困惑的是,函数中的图已绘制,但只有未显示的交互式窗口小部件。

import numpy as np            # Data manipulation
import pandas as pd           # Dataframe manipulatio 
import matplotlib.pyplot as plt # For graphics
import seaborn as sns
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

#calling the widget function here
interact(h, ctr=(0,8,2),resptime=(0,8,2),inpercons=(0,8,2));

#defining the widget function here

def h(ctr,resptime,inpercons):

total=ctr+resptime+inpercons

if total>20:
    custsatscores=[8,8,8,8,8,8,7,7,7,4]

if (total>10 and total<20):
    custsatscores=[7,7,7,7,7,7,8,8,8,4]

if total<10:
    custsatscores=[4,4,4,4,4,4,7,7,7,8]


newlist=[]



import random


for ii in range(10):



    dummylist=[]
    dummylist1=[]
    dummylist2=[]
    dummylist3=[]
    dummylist4=[]

    rr=[]



    for i in range(10):







        dummylist.append(random.randint(0,3))
        dummylist1.append(random.randint(1,4))
        dummylist2.append(random.randint(0,3))
        dummylist3.append(random.randint(0,3))
        dummylist4.append(random.randint(0,3))




    check=custsatscores[ii]




    if check<5:

        rr=[sorted(dummylist),sorted(dummylist1),sorted(dummylist2),sorted(dummylist3),
            sorted(dummylist4)]






    #Avg Satisfaction, Out of 15, 3 Random,1 opposite 

    elif check>4 and check<8:


        rr=[dummylist,sorted(dummylist1),sorted(dummylist2),sorted(dummylist3),
            sorted(dummylist4)]




    #Good Satisfaction, Out of 15, 2 Random 


    else:
        rr=[sorted(dummylist),dummylist1,sorted(dummylist2),sorted(dummylist3),
            sorted(dummylist4)]





    newlist.append(rr)


    #if(ii==9)

    #bookmark=[0,0,0,0,0,0,0,0,0]
    #newlist.append(bookmark)

da=pd.DataFrame()

appended_data = []

for i in range(10):
    data = newlist[i]

    npary=np.array(data)

    npary1=npary.T

    ddd=npary1.tolist()

    appended_data.append(npary1)



    da=da.append(ddd,ignore_index=False)

da.columns = [
  1,
  2,
  3,
 4,
5
]

a=0

countz=0
for ii in range(int(len(da)/10)):


    b=a+10
    e=da.iloc[a:b]

    #custsatscores
    #plt.title('Customer Satisfaction rating'+str(custsatscores[ii]))


    for i, col in enumerate(e.columns):

        plt.title('Customer Satisfaction rating'+str(custsatscores[ii]))


        plt.ylabel('% Patient number'+str(ii+1))

        plt.xlabel('Question number'+str(i+1))


        #plt.figure(i)
        plt.plot(e[col])
        plt.show()
        #print(i)


    a=a+10







return (ctr,resptime,inpercons)

1 个答案:

答案 0 :(得分:0)

大声笑我想通了,只需要删除末尾的分号即可。 下面的互动功能!

interact(h,ctr =(0,8,2),resptime =(0,8,2),inpercons =(0,8,2));