The following method is not available.
Many tutorials on the web are said to be modified in the configuration file:%python_home%LIB\SITE-PACKAGES\MATPLOTLIB\MPL-DATA\MATPLOTLIBRC (Windows)
Font.family:sans-serif #打开该选项
Font.sans-serif:microsoft Yahei, bitstream Vera sans, lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avan T Garde, Sans-serif
#添加 "Microsoft Yahei", which indicates the priority order of default fonts and fonts
Then copy the fonts into the Matplotlib\mpl-data\fonts\ttf folder
Finally, a tedious approach was found:
Import Matplotlib.font_manager as FMMYFONT = FM. Fontproperties (fname= ' C:/WINDOWS/FONTS/MSYH.TTC ') import Matplotlib.pyplot as PLTPLT.CLF () # empty Canvas Plt.plot ([1, 2, 3], [4, 5, 6]) Plt.xlabel ("Horizontal", Fontproperties=myfont) Plt.ylabel ("longitudinal axis", Fontproperties=myfont) plt.title ("pythoner.com ", Fontproperties=myfont) Legend ([' Legend '],prop=myfont) plt.show ()
Note that the font configuration for legend is prop, and the others are fontproperites.
This method is the only valid one.
If there is a more convenient way, please let us know.
Matplotlib Chinese display problem