Python matplotlib How to display Chinese in Mac OS X, perfect solution

Source: Internet
Author: User

First, download the relevant Chinese font Simhei file:

Second, find the Matplotlib data storage location by the following code:

Import matplotlib Print (Matplotlib.matplotlib_fname ())

My directory is: /VOLUMES/05/ANCONDA/ANACONDA3/LIB/PYTHON3.6/SITE-PACKAGES/MATPLOTLIB/MPL-DATA/MATPLOTLIBRC

Third, open the above directory, and copy the downloaded font file simhei.ttf to the fonts/ttf/ Directory of the above directory

Four, in the above directory with sublime open MATPLOTLIBRC, find #font. Sans-serif Start this line, remove the "#", and add Simhei, as follows

Font.sans-serif     Simhei, Dejavu sans, bitstream Vera sans, lucida Grande, Verdana, Geneva, Lucid, Arial, Helve TICA, Avant Garde, Sans-serif

Remove the comment from the #axes. Unicode_minus:true and change it to False, which causes the negative sign of the axis to be displayed if you do not modify it.

V. Perform RM-RF ~/.matplotlib/* on the terminal , and then restart python or Ipython

It took me a whole morning to get this, and in the other tutorials I just needed to do rm-rf ~/.matplotlib/*.cache, and I found that I couldn't because we added a new font, so we need to remove that JSON file as well.

Error message:

A. When no font specified in/matplotlib/mpl-data/fonts/ttf is executed, the following error occurs

Font_manager.py:1287:userwarning:findfont:font family [u ' Sans-serif '] not found.

Python matplotlib How to display Chinese in Mac OS X, perfect solution

Related Article

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.