matplotlib里中文乱码,试了多种方法仍未解决。最终替换字体文件解决。
1.找到使用的字体文件,找到源码font_manager.py。
font_manager.py中FontManager类的findfont函数中打印出返回的字体,我的返回的是:
/usr/lib64/python2.7/dist-packages/matplotlib-1.4.3-py2.7-linux-x86_64.egg/matplotlib/mpl-data/fonts/ttf/Vera.ttf
2. 找到windows下的simsun.ttc(宋体字体), 重命名成Vera.ttf,替换/usr/lib64/python2.7/dist-packages/matplotlib-1.4.3-py2.7-linux-x86_64.egg/matplotlib/mpl-data/fonts/ttf/Vera.ttf。
中文就出来了!