Matplotlib drawing does not display Chinese (solution)

Problem: When drawing with matplotlib, Chinese characters are not displayed, but frames.

Solution:

1. Enter the following code:

import matplotlib    
print(matplotlib.matplotlib_fname())

Check whether there are related Chinese fonts in C:\Users\...\Python\Python38\site-packages\matplotlib\mpl-data\fonts\tff.

2. If you don't have one, download one (valid for 30 days), and extract it to a tff file .

3. Open the C:\Users\...\Python\Python38\site-packages\matplotlib\mpl-data\ matplotlibrc file. Modify the following:

 font.family         : sans-serif   
 # 去掉前面的#     
 font.sans-serif     : SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif  
 # 去掉前面的#,并在冒号后面添加SimHei
 axes.unicode_minus  : False
 # 去掉前面的#,并将True改为False

4. Save, close and restart, it should be fine.


 Reference link:

Mac python matplotlib Glyph xxxxx missing from current font solution

Guess you like

Origin blog.csdn.net/baidu_30506559/article/details/122277715