0
点赞
收藏
分享

微信扫一扫

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

才德的女子 2022-01-27 阅读 52



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


  • ​​环境​​
  • ​​解决问题过程​​

  • ​​==Warning 信息==​​
  • ​​解决过程​​
  • ​​节外生枝 | 又出现一个新报错​​

  • ​​参考 | 小结​​


环境

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​​,并放到指定目录下。Matplotlib--UserWarning: findfont: Font family [u
    参考我的报错,我需要将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://github.com/matplotlib/matplotlib/issues/8876​​

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



举报

相关推荐

0 条评论