First, the Mac needs to download the Simhei.ttf font and install it, then follow the steps below to copy the Simhei.ttf to the ~python installation path/site-packages/matplotlib/mpl-data/fonts/ttf directory;
Link: Https://pan.baidu.com/s/1hsGhxmG Password: rste
Two. Then modify the ~python installation path/SITE-PACKAGES/MATPLOTLIB/MPL-DATA/MATPLOTLIBRC file. According to the actual situation changes, find the following two items, remove the previous #, and after the Font.sans-serif Colon plus simhei, save exit.
Font.family:sans-serif
Font.sans-serif:simhei, Bitstream Vera sans, lucida Grande,verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, SA Ns-serif
At the same time will find Axes.unicode_minus, will be true to false, the role is to solve the negative sign '-' Display as a block problem
Three. Add the following two paragraphs to the code
#matplotlib不会每次启动时都重新扫描所有的字体文件并创建字体索引列表,
# So after copying the font file, you need to run the following statement to recreate the font index list
From Matplotlib.font_manager import _rebuild
_rebuild ()
#防止中文乱码问题
mpl.rcparams[' Font.sans-serif ']=[u ' Simhei ']
mpl.rcparams[' Axes.unicode_minus ']=false
Solve the problem of matplotlib Chinese display block in Mac system