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

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