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獲取緩存地址。