Chinese display problem solved
Solution one:
Download Chinese fonts (in bold, look at the system version)
-
Step 1: Download the SimHei font (or other fonts that support Chinese display will also work)
-
Step 2: Install fonts
-
Under linux: copy fonts to usr/share/fonts:
sudo cp ~/SimHei.ttf /usr/share/fonts/SimHei.ttf
-
Windows and Mac: double-click to install
-
-
Step 3: Delete the cache file in ~/.matplotlib
cd ~/.matplotlib rm -r *
-
Step 4: Modify the configuration file matplotlibrc
vi ~/.matplotlib/matplotlibrc
Modify the content of the file to:
font.family : sans-serif font.sans-serif : SimHei axes.unicode_minus : False
Solution two:
Set matplotlibrc dynamically in the Python script, which can also avoid the trouble caused by changing the configuration file. The specific code is as follows:
from pylab import mpl
# 设置显示中文字体
mpl.rcParams["font.sans-serif"] = ["SimHei"]
Sometimes, after the font is changed, some characters in the coordinate axis cannot be displayed normally. At this time, you need to change the axes.unicode_minus parameter:
# 设置正常显示符号
mpl.rcParams["axes.unicode_minus"] = False