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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容