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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

99Kies

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值