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

完成!!!

相关文章:

  • 2021-04-07
  • 2021-09-27
  • 2021-09-02
  • 2021-07-28
  • 2022-01-08
  • 2021-10-10
  • 2021-11-14
  • 2021-10-08
猜你喜欢
  • 2021-10-30
  • 2021-08-19
  • 2021-10-04
  • 2021-12-23
  • 2021-08-06
  • 2021-07-20
  • 2021-10-11
相关资源
相似解决方案