Home > other >  ValueError: 'label' must be of length 'x'
ValueError: 'label' must be of length 'x'

Time:10-21

Is there anyone who can answer it why?
It worked the first, second not


Labels=[' optimal ', 'good', 'light pollution', 'moderate pollution', 'severe pollution]
,0,0.1 explodes=(0, 0.2, 0.3)
Data=https://bbs.csdn.net/topics/pd.read_csv (filePath + STR (I), index_col=False, encoding='GB2312' or 'utf8)
Data=data [' aql] [' quality grade]. The map (aql)
Data. The drop ([' quality grades'], axis=1, inplace=True)
For j in range (data. Shape [0]) :
If j %==0 and 365 j!=0:
Year_data=https://bbs.csdn.net/topics/data.iloc [j - 365: j]
PLT. RcParams [' font. Sans-serif]=[' SimHei]
PLT. RcParams [' axes. Unicode_minus]=False
Class_series=year_data. Groupby (" aql "). The size ()
PLT. Pie (class_series, autopct='% % % 1.1 f, labels=labels, explodes=explodes)
PLT. Savefig (' C: \ \ Users \ \ pc2019 \ \ AQI \ \ PIC \ \ '+ STR (I) [: - 8] + STR (int j/365) (+ 2013) +' PNG ')
PLT. The show ()




ValueError Traceback (the most recent call last)

16 PLT. RcParams [' axes. Unicode_minus]=False
17 class_series=year_data. Groupby (" aql "). The size ()
- & gt; 18 PLT. Pie (class_series, autopct='% % % 1.1 f, labels=labels, explodes=explodes)
19 PLT. Savefig (' C: \ \ Users \ \ pc2019 \ \ AQI \ \ PIC \ \ '+ STR (I) [: - 8] + STR (int j/365 + 2013) +' PNG ')
20 PLT. The show ()

C: \ users \ pc2019 \ appdata \ local \ designed \ python \ python37-32 \ lib \ site - packages \ matplotlib \ pyplot py pie in (x, explodes, labels, colors, autopct pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center, frame, rotatelabels, data)
2785 wedgeprops=wedgeprops textprops=textprops, center=center,
2786 frame=frame, rotatelabels=rotatelabels, * * ({" data ": data} if
-> 2787 the data is not None else {}))
2788
2789

C: \ users \ pc2019 \ appdata \ local \ designed \ python \ python37-32 \ lib \ site - packages \ matplotlib \ set py in inner (ax, data, * args, * * kwargs)
1599 def inner (ax, * args, data=https://bbs.csdn.net/topics/None, * * kwargs) :
1600 if the data is None:
-> 1601 return func (ax, * map (sanitize_sequence, args), * * kwargs)
1602
1603 bound=new_sig. Bind (ax, * args, * * kwargs)

C: \ users \ pc2019 \ appdata \ local \ designed \ python \ python37-32 \ lib \ site - packages \ matplotlib \ axes \ _axes py in pie (self, x, explodes, labels, colors, autopct, pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center, frame, rotatelabels)
2981 explodes=[0] * len (x)
2982 if len (x)!=len (labels) :
-> 2983 the -raise ValueError (" 'label' must be of length 'x' ")
2984 if len (x)!=len (explodes) :
2985 the -raise ValueError (" 'explodes' must be of length' x '")

ValueError: 'label' must be of length 'x'
  • Related