Matplotlib pyplot the title () xlabel () ylabel () can not display Chinese (box is displayed garbled) solution

Fun, Python will never miss!

For forwarding, please indicate the source: a small Tinger of Python    https://www.cnblogs.com/xxtalhr/p/11020246.html 

First, the cause can not be displayed correctly

               matplotlib.pyplot can not find the right font in the display, so garbled (my appear as boxes)

Second, the solution

Add the relevant package, specify the relevant font

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)

 

 

 result 

  Successfully !!!

  Fun, Python will never miss! Not to add me, look what Ne. Da da da. . .



For forwarding, please indicate the source: a small Tinger of Python    https://www.cnblogs.com/xxtalhr/p/11020246.html 
For forwarding, please indicate the source: a small Tinger of Python    https://www.cnblogs.com/xxtalhr/p/11020246.html 
For forwarding, please indicate the source: a small Tinger of Python    https://www.cnblogs.com/xxtalhr/p/11020246.html 
For forwarding, please indicate the source: a small Tinger of Python    https://www.cnblogs.com/xxtalhr/p/11020246.html 

Guess you like

Origin www.cnblogs.com/xxtalhr/p/11020246.html