在用python运行SVM代码的时候,控制台一直报错误:Font family [‘sans-serif‘] not found.Falling back to DejaVu Sans,找不到sans-serif字体
# 在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
https://www.fontpalace.com/font-download/SimHei/
将下载的字体复制进打开的目录中
# 在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