解决matplotlib问题: 没有'Times New Roman'字体


Matplotlib 中设置字体为Times New Roman 时报错:

UserWarning: findfont: Font family [u'Times New Roman'] not found. Falling back to DejaVu Sans   (prop.get_family(), self.defaultFamily[fontext]))

报错原因为系统中没有Times New Roman 这个字体。

解决方案:

(1)下载安装Times New Roman字体。

sudo apt install font-manager

(2)删除matplotlib的缓存:

rm ~/.cache/matplotlib -rf

注意:可能缓存地址不对,使用代码 fontmanager.get_cachedir() 或 fontmanager._fmcache获取缓存地址。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM