报错信息: UserWarning: findfont: Font family [u'sans-serif'] not found. Falling back to DejaVu Sans
Can not find fonts, Chinese garbled in drawing pictures
Solution:
1. Check the configuration path:
import matplotlib
print (matplotlib.matplotlib_fname())
2. Download font: simhei.tff: http://www.font5.com.cn/font_download.php?id=151&part=1237887120
3. tff fonts are copied to the directory:
/home/hwy/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/tff/
5. Remove the font cache files:
First find the location of the font cache files:
import matplotlib as mpl fm = mpl.font_manager fm.get_cachedir()
This is where I cache file:
/home/hwy/.cache/matplotlib/
Deleted like:
rm -rf /home/hwy/.cache/matplotlib/
6. font parameter settings:
Modify the configuration file matplotlibrc:
We will look at three modifications, and # remove:
font.family : sans-serif ... font.sans-serif : SimHei ... axes.unicode_minus : False # use unicode for the minus symbol
Meaning that the font family know as sans-serif, while adding "SimHei" that is Times New Roman font family to the list, and will find axes.unicode_minus, will be changed to True False, the role is to solve the minus sign '-' display box problem.
The success of the Chinese show! !
The following blog configured just fine.