MAC中python中文出现乱码方格——matplotlib画图

问题:中文出现乱码方格,添加下方代码也没法正常使用。
在这里插入图片描述

1
plt.rcParams['font.sans-serif'] = 'SimHei'

在这里插入图片描述
解决:
1、下载SimHei字体 —SimHei.tff
SimHei字体下载
2、将下载的文件复制到 /Library/Fonts(Mac 电脑:资源库/Fonts)
3、将下载的文件复制到 /Users/zhaxiaohui/anaconda3/pkgs/matplotlib-3.1.0-py37h54f8f79_0/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf
在这里插入图片描述
4、重新加载字体,在Python中运行如下代码即可:

1
2
from matplotlib.font_manager import _rebuild
_rebuild()

结果:
在这里插入图片描述