解决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获取缓存地址。

posted @ 2020-10-12 17:05  DGSX  阅读(6527)  评论(1编辑  收藏  举报