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

有錢、任性 2019-11-08 12:48:28
有没有哪位大佬能解答一下为什么会这样?
第一个还好好的,第二个就不行了


labels = ['优','良','轻度污染','中度污染','重度污染']
explode = (0,0,0.1,0.2,0.3)
data = pd.read_csv(filePath+str(i),index_col=False,encoding='GB2312'or'utf8')
data['aql']=data['质量等级'].map(aql)
data.drop(['质量等级'],axis=1,inplace=True)
for j in range(data.shape[0]):
if j%365==0 and j!=0:
year_data = data.iloc[j-365:j]
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
class_series = year_data.groupby('aql').size()
plt.pie(class_series,autopct='%1.1f%%',labels = labels,explode=explode)
plt.savefig('C:\\Users\\pc2019\\AQI\\pic\\'+str(i[:-8])+str(int(j/365)+2013)+'.png')
plt.show()




ValueError Traceback (most recent call last)
<ipython-input-17-7b939e27d91a> in <module>
16 plt.rcParams['axes.unicode_minus'] = False
17 class_series = year_data.groupby('aql').size()
---> 18 plt.pie(class_series,autopct='%1.1f%%',labels = labels,explode=explode)
19 plt.savefig('C:\\Users\\pc2019\\AQI\\pic\\'+str(i[:-8])+str(int(j/365)+2013)+'.png')
20 plt.show()

c:\users\pc2019\appdata\local\programs\python\python37-32\lib\site-packages\matplotlib\pyplot.py in pie(x, explode, 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 data is not None else {}))
2788
2789

c:\users\pc2019\appdata\local\programs\python\python37-32\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
1599 def inner(ax, *args, data=None, **kwargs):
1600 if 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\programs\python\python37-32\lib\site-packages\matplotlib\axes\_axes.py in pie(self, x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center, frame, rotatelabels)
2981 explode = [0] * len(x)
2982 if len(x) != len(labels):
-> 2983 raise ValueError("'label' must be of length 'x'")
2984 if len(x) != len(explode):
2985 raise ValueError("'explode' must be of length 'x'")

ValueError: 'label' must be of length 'x'
...全文
5935 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧