Python3 matplotlib 画图保存图片空白

Python3 matplotlib 画图保存图片空白

原因是因为保存图片的时候将plt.savefig('./test.jpg')放到了plt.show()之后

# 从低到高展示成绩分布图
grade_distribution = sns.countplot(student['G3'])
grade_distribution.set_title('成绩分布图', fontsize=30)
grade_distribution.set_xlabel('期末成绩', fontsize=20)
grade_distribution.set_ylabel('人数统计', fontsize=20)
# 保存图片
plt.savefig('./从低到高展示成绩分布图.jpg')
plt.show()

只要颠倒顺序,在plt.show()之前plt.savefig('./test.jpg')

 
发布了496 篇原创文章 · 获赞 464 · 访问量 86万+

猜你喜欢

转载自blog.csdn.net/zhangvalue/article/details/103936029