jupyter notebook中matplotlib绘图包的中文乱码问题

方法1,root态安装

  1. 停止Jupyter
  2. 安装 font-manager: sudo apt install font-manager
  3. 清除matplotlib cache directory: rm ~/.cache/matplotlib -fr
  4. 重启Jupyter.

方法2,用户态安装

1. 查找matplotlib路径

import matplotlib
matplotlib.matplotlib_fname()

输出路径大致如下,记住,第2步会使用:

'xxx/matplotlib/mpl-data/matplotlibrc'

2. 安装SimHei字体

字体链接:百度网盘 密码:5vn4

字体放到xxx/matplotlib/mpl-data/ttf下即可

3. 修改配置文件

vim 打开xxx/matplotlib/matplotlibrc,添加内容如下:

image

4. 删除缓存

rm ~/.cache/matplotlib -fr

重启jupyter即可。

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