报错信息
findfont: Font family ['sans-serif'] not found.
或
missing from current font.
报错原因
没有中文字体
解决方案及步骤
本方案是下载字体放入matplotlib的字体路径下面,一劳永逸的做法。
1. 下载字体
http://www.fontpalace.com/font-download/SimHei/
2. 复制字体到matplotlib字体目录下
matplotlib字体目录在哪?根据你的python路径查找,或者查看报错中给出的路径。我使用的anaconda的python环境,路径:
cp SimHei.ttf /anaconda2/envs/py3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf
3. 修改matplotlibrc配置文件
查找matplotlibrc配置文件位置的方法:终端运行python,执行如下命令
In