円グラフは、中国の文字化けを解決するためのpython生成

ゴミ問題を解決します

文字化けの理由

不一致のフォント

ソリューション

  • 中国語フォントのようなプラスの参照
 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()

効果

おすすめ

転載: www.cnblogs.com/mengxiaoleng/p/11695069.html