ubuntu解决matplotlit中文乱码的问题! 文章目录 simhei.ttf字体下载链接:http://xiazaiziti.com/210356.html将字体放到合适的地方 sudo cp SimHei.ttf /usr/share/fonts/(base) zkf@zkf:~$ fc-list | grep -i "SimHei" /usr/local/share/fonts/SimHei.ttf: SimHei,黑体:style=Regular 删除matplotlib缓存 – 查看缓存文件在哪里 强制清除并重建 Matplotlib 字体缓存 import matplotlib as mpl mpl.font_manager._rebuild() 或者在终端运行: rm ~/.cache/matplotlib -rf 完整代码示例 import matplotlib.pyplot as plt import matplotlib as mpl# 方案1:重建缓存 mpl.font_manager._rebuild()# 方案2:明确指定字体 plt.rcParams["font.sans-serif"] = ["SimHei"] # 或者使用绝对路径 plt.rcParams["axes.unicode_minus"] = False# 测试绘图 plt.plot([1, 2, 3], label="测试中文") plt.legend() plt.show() Matplotlib 中文乱码解决方案教程