解决ubuntu使用python库matplotlib中文乱码问题

1. 下载simhei.ttf字体

https://download.csdn.net/download/wei_love_2017/11183559

2. 找到matplotlib的安装目录

我的在 /usr/local/lib/python2.7/dist-packages/matplotlib

进入该目录的子目录中:/mpl-data/fonts/ttf

把下载的字体拷贝放到该目录中:/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/fonts/ttf

3. 编写matplotlib/mpl-data目录下的matplotlibrc文件

$ cd /usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data
$ sudo vim matplotlibrc

在193行输入如下内容:

font.family         : sans-serif
194 font.sans-serif     : SimHei
195 axes.unicode_minus  : False 

解决ubuntu使用python库matplotlib中文乱码问题

4. 删除~/.cache/matplotlib

$ rm -rf ~/.cache/matplotlib

完成!!!