解决 matplotlib 不支持中文字符
问题
matplotlib
默认使用的 DejaVu Sans
字体不支持中文字符,导致生成混淆矩阵图片时,无法正确显示包含中文的标签或文件名。
解决方法
手动设置支持中文的字体(推荐),加入以下代码,确保 matplotlib
使用支持中文的字体来渲染:
import matplotlib.font_manager as fm
plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置黑体
plt.rcParams['axes.unicode_minus'] = False # 解决负号显示问题