Python matplotlib how to display Chinese, minus sign
Today, when I tried to output Chinese in matplotlib drawing, I found that an error is reported and the solution is recorded as follows
1. Add at the top of the .py file
#-*- coding: utf-8 -*-
To modify the encoding
2. Then add at the head of the file
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
You're done!
Attach the font description:
Chinese font | Explanation |
---|---|
'SimHei' | Chinese bold |
'Kaiti' | Chinese italics |
'LiSu' | Chinese Lishu |
'FangSong' | Chinese imitation song |
'YouYuan' | Chinese Young Yuan |
STSong | Chinese Times New Roman |