python 中 matplotlib.pyplot 绘图中文乱码问题
解决办法:
加入以下两行代码:
plt.rcParams['font.sans-serif']=['simhei‘]
plt.rcParams['axes.unicode_minus']=False
【小知识】
查找本地系统上可以显示中文的字体:
python是自带可以显示中文的字体的,输入如下代码可>以查看系统中可以显示中文的可用字体。
from matplotlib.font_manager import FontManager fm = FontManager() mat_fonts = set(f.name for f in fm.ttflist) print('我的电脑上能显示中文的字体有:',mat_fonts)