Python数据可视化——matplotlib绘制的图里面不能正常显示中文,提示警告的解决方法
运行下列代码:import matplotlib.pyplot as pltedu = [0.2515,0.3724,0.3336,0.0368,0.0057]labels = ['中专','大专','本科','硕士','其他']plt.pie(x=edu,labels=labels,autopct='%.1f%%')plt.show()会出现:RuntimeWarning: Glyph 2001
·
运行下列代码:
import matplotlib.pyplot as plt
edu = [0.2515,0.3724,0.3336,0.0368,0.0057]
labels = ['中专','大专','本科','硕士','其他']
plt.pie(x=edu,labels=labels,autopct='%.1f%%')
plt.show()
会出现:
RuntimeWarning: Glyph 20013 missing from current font. font.set_text(s, 0.0, flags=flags)
这是matplotlib绘制的图里面不能正常显示中文,提示警告
matplotlib绘图中文警告
【解决方法】:
import matplotlib.pyplot as plt
edu = [0.2515,0.3724,0.3336,0.0368,0.0057]
labels = ['中专','大专','本科','硕士','其他']
plt.pie(x=edu,labels=labels,autopct='%.1f%%')
plt.rcParams['font.sans-serif']=['SimHei']#显示中文标签
#plt.rcParams['font.sans-serif']=['Microsoft YaHei'] #写这个也可以显示中文标签
plt.show()
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)