无法绘制我想要的内容

wz3gfoph  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(172)

我需要用复选按钮绘制一个图,但有些东西不起作用,有人能帮我吗?这是我的密码

import numpy as np
import pandas as pd
import seaborn as sn
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from matplotlib.widgets import CheckButtons

data=pd.read_csv('top10MX.csv')
data=pd.DataFrame(data=data)
data.set_index('Torneo',inplace=True)
data

[enter image description here][1]
This image is the data,is an 8x10 matrix

x=range(2014,2021,1)
y=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]

y1=data["Atlas"].values
y2=data["Club America"].values
y3=data["Cruz Azul"].values
y4=data["Guadalajara"].values
y5=data["Leon"].values
y6=data["Monterrey"].values
y7=data["Necaxa"].values
y8=data["Pumas"].values
y9=data["Tigres UANL"].values
y10=data["Toluca"].values

fig,ax=plt.subplots()
p1,=ax.plot(x,y1,color="lightcoral",label="Atlas",visible=True)
p2,=ax.plot(x,y1,color="yellow",label="Club America",visible=True)
p3,=ax.plot(x,y1,color="blue",label="Cruz Azul",visible=False)
p4,=ax.plot(x,y1,color="red",label="Guadalajara",visible=False)
p5,=ax.plot(x,y1,color="forestgreen",label="Leon",visible=False)
p6,=ax.plot(x,y1,color="dodgerblue",label="Monterrey",visible=False)
p7,=ax.plot(x,y1,color="orangered",label="Necaxa",visible=False)
p8,=ax.plot(x,y1,color="gold",label="Pumas",visible=False)
p9,=ax.plot(x,y1,color="darkorange",label="Tigres UANL",visible=False)
p10,=ax.plot(x,y1,color="tomato",label="Toluca",visible=False)
lines=[p1,p2,p3,p4,p5,p6,p7,p8,p9,p10]

plt.axis([2014,2020,1,18])
plt.ylabel("Posicion final en el torneo",fontsize=14)
plt.xlabel("Torneo",fontsize=14)
plt.yticks(np.arange(min(y), max(y)+2, 2))
plt.title('Top 10 most popular MX teams in torneos clausura 2014-2020',fontsize=18)
plt.legend(bbox_to_anchor=(1.001,1),ncol=1,fontsize=12)
plt.gca().invert_yaxis()

labels=["Atlas","Club America","Cruz Azul","Guadalajara","Leon","Monterrey","Necaxa","Pumas","Tigres UANL","Toluca"]
activated=[True,True,False,False,False,False,False,False,False,False]
axCheckButton=plt.axes([1.13,0.47,0.3,0.4])
chxbox=CheckButtons(axCheckButton,labels,activated)

def set_visible(label):
    index=labels.index(label)
    lines[index].set_visible(not lines[index].get_visible())
    plt.draw()

chxbox.on_clicked(set_visible)

plt.show()

在这里输入image description这是我得到的,理论上它应该绘制前两列的数据,而不是只绘制第一列的数据,复选按钮不起作用
有什么建议吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题