import matplotlib.pyplot as plt
import matplotlib

出现中文乱码原因:
matplotlib中找不到中文字体
解决方法:
1.找到中文字体文件的地址和字体文件名
通常:C:\Windows\Fonts\字体文件名
2.加载字体
    zh_font = matplotlib.font_manager.FontProperties(fname='C:\Windows\Fonts\simfang.ttf')
3.中文显示增加字体属性
  例如:
  plt.title(u'混淆矩阵',fontproperties=zh_font)
  plt.ylabel(u'实际类型',fontproperties=zh_font)
  plt.xlabel(u'预测类型',fontproperties=zh_font)
另一种解决:
# 加这个两句 可以显示中文 
plt.rcParams['font.sans-serif'] = [u'SimHei']
plt.rcParams['axes.unicode_minus'] = False

相关文章:

  • 2022-12-23
  • 2021-10-14
  • 2021-07-31
  • 2021-08-02
  • 2022-12-23
  • 2021-12-08
  • 2021-08-22
  • 2021-06-20
猜你喜欢
  • 2022-12-23
  • 2021-05-06
  • 2022-12-23
  • 2021-11-15
  • 2021-09-13
  • 2021-12-14
相关资源
相似解决方案