Reason: The default font for Matplotlib is not Chinese.

Solution: Set a Chinese font as the default preferred font. For this article, the default font will be Microsoft Yahei.

Environment: Win7 x64, PYTHon2.7

Process:

  1. Find the configuration file in python’s installation directory: % Python_Home % \ Lib \ site – packages \ matplotlib \ MPL – data \ matplotlibrc (e.g., Mine is opened in D: Python32\Lib\site-packages\matplotlib\mpl-data) with any text editor. (You’d better back it up first)
  2. Find line 129: #font. Family, comment it out and change the value after the colon to Microsoft YaHei
  3. Find line 141: #font. Sans-serif, comment it out and add Microsoft YaHei at the beginning of the colon, adding a comma (,)
  4. In the meantime, go to C:\Windows\Fonts\ find the Microsoft Ya-hite corresponding font file msyh. TTF and copy it to D:\ python32\ Lib\site-packages\matplotlib\mpl-data\ Fonts\ TTF \
  5. After the software is closed, open it again, run the program, and the display is normal.