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