Matplotlib pyplot中title() xlabel() ylabel()无法显示中文(即显示方框乱码)的解决办法

有趣的事,Python永远不会缺席!

如需转发,请注明出处:小婷儿的python  https://www.cnblogs.com/xxtalhr/p/11020246.html 

一、无法正常显示原因

               matplotlib.pyplot在显示时无法找到合适的字体,故显示乱码(我的显示为方框)

二、解决办法

添加相关包,指定相关字体

1 from matplotlib import pyplot
2 from matplotlib.font_manager import FontProperties
3 font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=15)
4 
5 pyplot.title(u'中文', fontproperties=font_set)
6 pyplot.xlabel(u'中文', fontproperties=font_set)
7 pyplot.ylabel(u'中文', fontproperties=font_set)

 

 

 结果 

  Successfully !!!

  有趣的事,Python永远不会缺席!还不来加我,瞅什么Ne。哒哒哒。。。



posted @ 2019-06-13 22:57  小婷儿  阅读(2803)  评论(0编辑  收藏  举报
levels of contents