解決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