如何解决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