Matplotlib.pyplot Plug-in Chinses Font Error: RuntimeWarning: Glyph 26376 missing from current font

Using Matplotlib When drawing with pyplot, add a Chinese font, which indicates that the font cannot be found. The solution is as follows

1. Download simhei Ttf (BOLD) font file;

2. Copy to D:\Python38\Lib\site-packages\matplotlib\mpl-data\fonts\ttf (My Catalog)

3. Modify the file D:\Python38\Lib\site-packages\matplotlib\mpl-data\matplotlibrc

 font.family         : sans-serif   
 # remove the previous #     
 font.sans-serif     : SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif  
 # remove the previous #, and add SimHei after the colon
 axes.unicode_minus  : False
 # remove the previous #, and change the True to False

4. Add code

# set the font
plt.rcParams['font.sans-serif'] = ['KaiTi', 'SimHei', 'FangSong'] 
plt.rcParams['font.size'] = 12 
plt.rcParams['axes.unicode_minus'] = False

5. Delete the buffer directory of Matplotlib
in the python environment of the terminal, enter the following command to view the font cache path of Matplotlib:

import matplotlib
matplotlib.get_cachedir()

Then exit the python environment and delete the cache directory on the terminal using the RM - RF + path

6. The font configuration is completed and can be used normally

Similar Posts: