如何解決python 圖表中文顯示亂碼問題(matlplotlib 包)


目前搜到的是,下載一個字體到程序路徑,設置成默認字體。  https://blog.csdn.net/irene_loong/article/details/68955485

 

#圖表顯示中文設置
import matplotlib as mpl # 新增包
from matplotlib.ticker import MultipleLocator, FormatStrFormatter #新增函數
mpl.rcParams['font.size'] = 15 # 設置字體大小
custom_font = mpl.font_manager.FontProperties(fname='../cj_data/ttf/msyh.ttf') #導入下載的字體文件

 

# 混淆矩陣 - 二元分類效果評估方法
y_true1=list(y_test)[:100]
cm = confusion_matrix(y_true1, y_pre)
plt.matshow(cm)
plt.title(u'混淆矩陣',fontproperties=custom_font)
plt.colorbar()
plt.ylabel(u'實際類型',fontproperties=custom_font)
plt.xlabel(u'預測類型',fontproperties=custom_font)
plt.show()

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM