matplotlib 中如下设置不起作用,还是显示不了中文
plt.rcParams['font.sans-serif']=['FangSong'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
解决方案:
# 查询当前系统所有字体
from matplotlib.font_manager import FontManager
mpl_fonts = set(f.name for f in FontManager().ttflist)
print('all font list get from matplotlib.font_manager:')
for f in sorted(mpl_fonts):
print('\t' + f)
设置如下:
matplotlib.rc("font",family='FangSong')
问题解决。