hcnak.blog

posted at 2016-08-31 15:27:05 +0000

Python matplotlib pyplot无法显示在中文(显示为方框)解决办法

无法显示中文,大概如下图中顶部的样子:

figure_1

在网上搜索一番,提到的大多数解决方式都不可用,类似于下面这样:

pyplot.title(u"中文") pyplot.title(u'\u4e2d\u6587') # (unicode编码) 
pyplot.title('\xe4\xb8\xad\xe6\x96\x87') # (utf-8编码)

如下:

from matplotlib import pyplot  
from matplotlib.font_manager import FontProperties  
font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=15)

pyplot.title(u'中文', fontproperties=font_set)

然后就完美解决了无法显示中文的问题。

figure_1

参考来源:http://blog.csdn.net/garfielder007/article/details/51405139



© kanchzl AT kanchz DOT com

last updated on 2022-07-27 01:57:54 +0000