Problem: Chinese garbled characters when drawing in matplotlib
Solution one:
Under windows, generally add the following two lines of code before the code to solve
plt.rcParams['font.sans-serif'] = ['simhei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
Solution two:
Under linux, you may need to manually configure fonts
1. Go to the official website https://www.fontpalace.com/font-download/SimHei/ to download SimHei
2. View font path in python terminal environment
3. According to the path in the previous step, enter the following directory and place the installation package in this directory
4. View the font cache path
5. Delete the cache
rm -rf /root/.cache/matplotlib
6. Modify the following three items in vi /usr/local/lib/python3.7/lib-dynload/matplotlib/mpl-data/matplotlibrc
font.family: sans-serif # Remove the comment
font.sans-serif: SimHei # Remove the comment and add SimHei
axes.unicode_minus: False # Remove the comment and modify it to False