解決亂碼問題
亂碼的原因
字體的不匹配
解決的方法
- 加上引用中文字體就好了
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()