解决乱码问题
乱码的原因
字体的不匹配
解决的方法
- 加上引用中文字体就好了
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
代码
def statistic_div_num():
mysql=MysqlConnect()
chinfo = matplotlib.font_manager.FontProperties(fname='C:/Windows/Fonts/STXINGKA.TTF')
area_type=['动画','国漫相关','音乐','舞蹈','游戏','科技','数码','生活','鬼畜','时尚','娱乐','影视']
url_Dict=getURLFormBilibili()
counts=[]
for type in area_type:
count=0
for table_Name in url_Dict.keys():
if type in table_Name:
getNameSql=mysql.getTableItemNum(table_Name)
print(mysql.queryOutCome(getNameSql)[0][0])
count+=mysql.queryOutCome(getNameSql)[0][0]
counts.append(count)
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
plt.pie(counts,labels=area_type,autopct='%1.1f%%')
plt.show()