python generate pie charts solve the Chinese garbled

Solve the garbage problem

Garbled reasons

Mismatched fonts

the solution

  • Plus references like Chinese fonts
 matplotlib.rcParams['font.sans-serif'] = ['SimHei']

Code

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()

effect

Guess you like

Origin www.cnblogs.com/mengxiaoleng/p/11695069.html