Font family ['sans-serif'] not found.Falling back to DejaVu Sans.解决办法

1、在终端python 的环境下,查看字体路径

import matplotlib    
print(matplotlib.matplotlib_fname())

Font family ['sans-serif'] not found.Falling back to DejaVu Sans.解决办法_第1张图片
2、下载SimHei
官方下载网址,并前往指定目录:/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf,将下载好的SimHei移动到该目录下。
3、删除matplotlib的缓冲目录
在终端python 的环境下,输入如下指令,查看matplotlib的字体缓存路径:

import matplotlib
matplotlib.get_cachedir()

然后使用rm -rf +路径删除缓存
Font family ['sans-serif'] not found.Falling back to DejaVu Sans.解决办法_第2张图片
4、修改matplotlibrc文件
修改/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-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  
 # 去掉前面的#,并在冒号后面添加SimHei
 axes.unicode_minus  : False
 # 去掉前面的#,并将True改为False

5、重新启动Eclipse。

你可能感兴趣的:(机器学习,python)