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
版权声明:本文标题:ubuntu安装中文字体,python plt 绘图显示中文 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1728201379a1149422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论