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

  

原文地址:https://www.cnblogs.com/skyEva/p/9629354.html