解决在matplotlib使用中文的问题

原生的matplotlib并不支持直接使用中文,而需要修改一下相应的文件,上网搜了下,找到一个最简洁的办法。

 

NO.1

找到matplotlibrc文件


C:\Python26\Lib\site-packages\matplotlib\mpl-data\matplotlibrc(Windows)


/usr/share/matplotlib/mpl-data/matplotlibrc (Linux)

 

NO.2

找到以下两项,去掉#

 

font.family         : sans-serif       

font.sans-serif     : Microsoft YaHei , Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif     #添加“Microsoft YaHei”,该行指示缺省字体

 

 

NO.3 

在写code的时候记得在字符串前加上u,表示unicode编码,例如:

setupGraph( 
           title="Speed of Train ", 
           xlabel=u'Time  单位:s', 
           ylabel=u"Speed  单位:m/s",                       
           hold=True 
       )

posted @ 2014-11-03 20:42  yyxayz  阅读(193)  评论(0编辑  收藏  举报