matplotlib 中文乱码

  1. 执行下面的代码找到配置文件路径
 import matplotlib
 matplotlib.matplotlib_fname()

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/mpl-data/matplotlibrc

  1. 修改 matplotlibrc 文件
    font.family : sans-serif
    font.sans-serif : SimHei, sans-serif
    把本机的中文字体放在 font.sans-serif 的最前面,如这里的 SimHei
  2. 如果找不到本机的中文字体,就下载一个 http://www.fontpalace.com/font-details/SimHei/
    放到 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf 文件夹下
  3. 重启 jupyter notebook

你可能感兴趣的:(matplotlib 中文乱码)