MacOS under Matplotlib Chinese garbled

Source: Internet
Author: User

The first step is to copy the font file to the file directory and delete the Matplolib font cache file

 ~\site-packages\matplotlib\mpl-data\fonts\ttf\(就是这)

Import matplotlib Print (Matplotlib.matplotlib_fname ()) # The path is displayed ~\site-packages\matplotlib\mpl-data

Other people on the Internet do not copy font files into the directory under Windows, but I must copy them under the Mac, I do not know why.然后就是删除~/.cache/matplotlib/下的文件

The second step is to modify the font_manager.py source file under Matplotlib to fit the *.TTC font file

defget_fontext_synonyms (fontext):"""Return A list of file extensions extensions that is synonyms for the given file extension *fileext*. """    return{'TTF': ('TTF','OTF'),#This line is changed to ' TTF ': (' ttf ', ' OTF ', ' TTC '),            'OTF': ('TTF','OTF'),            'AFM': ('AFM',)}[fontext]

If you use *.ttf fonts, do not change

Step Three

MyFont = Matplotlib.font_manager. Fontproperties (fname='/SYSTEM/LIBRARY/FONTS/PINGFANG.TTC')Print(Myfont.get_name ())#=>pingfang HKmatplotlib.rcparams['Font.sans-serif'] ='Pingfang HK'matplotlib.rcparams['Axes.unicode_minus'] = False#-SymbolsPlt.title ("haha") plt.show ()

PINGFANG.TTC file to be copied into the TTF folder under Matplotlib, the font name and font file name may not be the same, it is better to check first

Finally who knows whether the font file can not be copied into the Mp-data folder?

MacOS under Matplotlib Chinese garbled

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.