解决Font family [‘sans-serif‘] not found.Falling back to DejaVu Sans
在用python运行SVM代码的时候,控制台一直报错误:Font family [‘sans-serif‘] not found.Falling back to DejaVu Sans,找不到sans-serif字体
一、获取matplotlib的字体目录
# 在python终端中输入
import patplotlib
print(matplotlib.matplotlib_fname())
# 输出结果
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
二、打开字体目录
open /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf
三、下载SimHei字体
https://www.fontpalace.com/font-download/SimHei/
将下载的字体复制进打开的目录中
四、清除matplotlib缓存
# 在python终端中
import matplotlib
matplotlib.get_cachedir()
# 输出结果
'/Users/aaa/.matplotlib'
rm -rf /Users/test/.matplotlib
五、修改配置文件
vim /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
通过查找命令查找font.family
:/font.family
# 删除前面的#号
font.family: sans-serif
# 删除前面的#号,并在后面添加SimHei
font.serif: SimHei, DejaVu Serif, Bitstream Vera Serif, Computer Modern Roman, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
# 将True盖为False
axes.unicode_minus: False