1. 在windows的c:\windows\fonts下找一些中文字体,要后缀是ttf的字体文件。
simhei.ttf simkai.ttf simli.TTF simyou.TTF
2. 把上述ttf文件,复制到
/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/fonts/ttf
3. 在python2.7运行
python2.7
Python 2.7.12 (default, Nov 20 2017, 18:23:56)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> print matplotlib.matplotlib_fname()
/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc
文件/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc是字体配置信息。
4. 修改 /usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc是字体配置信息。
4.1 打开该配置文件,找到下面两行:
font.serif : simkai, DejaVu Serif, Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookm