1. 获取matplotlib所在的文件夹
import matplotlib
matplotlib.matplotlib_fname() #将会获得matplotlib包所在文件夹
2. 拷贝字体
将SimHei.ttf (可以在windows电脑上搜索找到
)拷贝到 ~/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf
3. 修改配置文件
vi ~/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
# 查找如下行,去掉注释,注册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
font.sans-serif : SimHei, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial,
axes.unicode_minus : False ## use unicode for the minus symbol 用来正常显示负号
4. 进入 ~/.cache/matplotlib 目录下,并删除matplotlib 下的fontList.josn
5. 重启python
6. 设置字体
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
sns.set(font='SimHei')