Matplotlib findfont: Font family [u‘sans-serif‘] not found
阿新 • • 發佈:2021-02-04
技術標籤:Python
Matplotlib使用UserWarning:findfont: Font family [u'sans-serif'] not found
環境
Ubuntu16.04
python3.5
matplotlib
解決問題過程
Warning 資訊
我利用matplotlib編寫了一個十分簡單的畫圖指令碼,但是遇到了這個報錯
UserWarning: findfont: Font family [u'sans-serif'] not found. Falling back to DejaVu Sans (prop.get_family(), self.defaultFamily[fontext]))
解決過程
- 下載SimHei.ttfDownload,並放到指定目錄下。
需要將SimHei.ttf放在/usr/lib/python3/dist-packages/matplotlib/mpl-data/fonts/ttf中。
2.修改/usr/lib/python3/dist-packages/matplotlib/mpl-data/matplotlibrc的內容
font.family : sans-serif font.sans-serif : SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif axes.unicode_minus,將True改為False,作用就是解決負號'-'顯示為方塊的問題
3.刪除~/.cache/matplotlib的緩衝目錄
rm -rf ~/.cache/matplotlib
4.重啟服務
重啟之後我又碰到了另外一個報錯
/usr/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
解決方法:
sudo apt-get install libfreetype6-dev libxft-dev
參考 | 小結
https://blog.csdn.net/dgatiger/article/details/50414549