admin管理员组

文章数量:1594755

step1:下载字体simhei.ttf和simkai.ttf

        链接:百度云 
        提取码:i3pe

或者在一台win10电脑中查找,查找路径是:C:/Windows/fonts.

 

step2:将字体上传到服务器,上传位置“/home/wzg/Downloads/fonts/”

        我用的是winscp软件,大家应该都有不同的方法。

step3:将字体文件复制到指定文件夹, "/usr/share/fonts/truetype/noto/", 别的路径可能无效。

cd /home/wzg/Downloads/fonts
sudo cp -i simhei.ttf /usr/share/fonts/truetype/noto/
sudo cp -i simkai.ttf /usr/share/fonts/truetype/noto/

step4:删除字体路径缓存(当运行新程序时会重新生成)

cd /home/wzg/.cache
rm -rf matplotlib

step5:在脚本中添加以下代码,然后运行程序。

import matplotlib
matplotlib.rcParams['font.sans-serif'] = ['SimHei'] #或者把"SimHei"换为"KaiTi"
matplotlib.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题

此时应该就可以显示中文了。


参考:Matplotlib不能显示中文 — Font family ['sans-serif'] not found警告_wtySama的博客-CSDN博客_matplotlib不识别中文

Win10下findfont: Font family [‘sans-serif‘] not found中文显示问题解决方法_weixin_45690427的博客-CSDN博客  python经典字体警告:RuntimeWarning: Glyph missing from current font. font.set_text(s, 0.0, flags=flags)_lavender_dream的博客-CSDN博客_glyph

本文标签: 中文中文字体UbuntupltPython