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:
- [Solved] Runtime Warning: Font Glyph 20108 is missing. Font.set Fu text (s,0.0,flags=flags), RuntimeWarningGlyph20108missingfromcurrentfontfontsettexts00flagsflags
- ModuleNotFoundError: No module named ‘PyQt4’ [Spyder Import matplotlib Error]
- Solve the problem of attributeerror: module ‘Matplotlib’ has no attribute ‘verb
- RuntimeError: Python is not installed as a framework [How to Solve]
- How to Solve Ajax Error 500 (Internal Server Error)
- ImportError: cannot import name cbook
- [Solved] Ride.py startup error: Error in atexit._run_exitfuncs
- [Solved] Captcha Library Error: “OSError: cannot open resource”
- PIP install troubleshooting under Windows [How to Solve]
- Oserror: cannot open resource (pilot error handling)