Matplotlib--UserWarning: findfont: Font family [u'sans-serif'] not found.

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]))

解決過程

  1. 下載SimHei.ttf Download,並放到指定目錄下。在這裏插入圖片描述
    參考我的報錯,我需要將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,作用就是解決負號'-'顯示爲方塊的問題   
  1. 刪除~/.cache/matplotlib的緩衝目錄
rm -rf ~/.cache/matplotlib
  1. 重啓服務

這就解決問題了,可是 重啓之後我又碰到了另外一個報錯

節外生枝 | 又出現一個新報錯

/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

https://github.com/matplotlib/matplotlib/issues/8876

http://wenda.chinahadoop.cn/question/6828

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章