ValueError:“标签”的长度必须为“ x”

时间:2019-03-25 09:24:52

标签: python jupyter-notebook

我想绘制饼图,但出现ValueError:“标签”的长度必须为“ x” ...而且我不明白为什么,因为我的长度相同...错误是指向颜色的。你能帮我吗?

@widgets.interact(
    team1=["Argentina","Austria","Belgium","Brazil","Bulgaria","Chile","Czechoslovakia","England",
           "France","Germany","Hungary","Italy","Korea Republic","Mexico","Netherlands","Paraguay",
           "Poland","Portugal","Russia","Spain","Sweden","Switzerland","Uruguay","USA","Yugoslavia"],)

def teams_performance(team1="Austria"):
    lst = [team1]
    length = len(team1)
    qtr = mat_new[mat_new["team"].isin(lst)]

    plt.figure(figsize=(12,8))

    for i,j in itertools.zip_longest(team1,range(length)) : 
        plt.subplot(221)
        lab = ["wins","draws","loses"]
        plt.pie(qtr[qtr["team"] == i][lab].values.ravel(),
                explode = None,
                labels  = lab , 
                autopct = "%1.0f%%",
                shadow  = True,
                wedgeprops = {"linewidth":3.5,"edgecolor":"white"},
                colors  = ["lawngreen","royalblue","tomato"],)

    circ = plt.Circle((0,0),.7,color="white")
    plt.gca().add_artist(circ)

    plt.title(i,color="navy",fontsize=14)

这是问题所在...

     20                 shadow  = True,
     21                 wedgeprops = {"linewidth":3.5,"edgecolor":"white"},
---> 22                 colors  = ["lawngreen","royalblue","tomato"],)
     23 
     24     circ = plt.Circle((0,0),.7,color="white")
ValueError: 'label' must be of length 'x'

0 个答案:

没有答案