virtualenv下解决matplotlib中文乱码

1. 安装中文字体

一般系统自带wqy-microhei,其ttc文件位于/usr/share/fonts/truetype/wqy/wqy-microhei.ttc

2. 将ttc文件复制到python文件目录

sudo cp /usr/share/fonts/truetype/wqy/wqy-microhei.ttc ./

 3. 在python文件中加上

 

# -*- coding: utf-8 -*-

import os.path
from matplotlib.font_manager import FontProperties
zh_font = FontProperties(fname=os.path.abspath('wqy-microhei.ttc'))
import matplotlib.pyplot as plt
plt.title(u'中文', fontproperties=zh_font)

 

 参考:http://andresabino.com/2015/08/18/fonts-and-matplotlib/

 

posted @ 2016-04-02 13:23  lireagan  阅读(578)  评论(0编辑  收藏  举报