Matplotlib Chinese display problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.