matplotlib使用中文字体

matplotlib中本身是不支持中文的(utf-8都不行吗),但是我们可以通过一定的方法进行解决

from matplotlib import font_manager

# fname 指定为系统中支持中文的字体
my_font = font_manager.FontProperties(fname=r"C:\Windows\Fonts\msyhl.ttc") 
# 调用的时候指定 fontproperties即可
plt.title("图形图像", fontproperties=my_font)

但是在plt.legend中需要使用prop

plt.legend(prop=my_font)
发布了123 篇原创文章 · 获赞 31 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44676081/article/details/104301817