1. 找到matplotlib 配置文件:
import matplotlib
print(matplotlib.matplotlib_fname())
E:\software\python\anaconda\lib\site-packages\matplotlib\mpl-data\matplotlibrc
2. 编辑上述文件,uncomment the following 2 lines
font.family : sans-serif
font.sans-serif : DejaVu Sans, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
3. http://font.chinaz.com/161111131720.htm 下载字体:msyh.ttf (微软雅黑)
放在E:\software\python\anaconda\Lib\site-packages\matplotlib\mpl-data\fonts\ttf
4. 删除.matplotlib/cache里面的两个缓存字体文件
file:///C:/Users/Administrator/.matplotlib/tex.cache
file:///C:/Users/Administrator/.matplotlib/fontList.json
5. 重启Python
6. 代码中添加plt.rcParams['font.sans-serif']=['Microsoft YaHei']