为什么 Matplotlib savefig 图像重叠? [英] Why does Matplotlib savefig images overlap?

查看:46
本文介绍了为什么 Matplotlib savefig 图像重叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中构建了一个使用 Tkinter 的 GUI 应用程序.

I have built a GUI app in python which uses Tkinter.

此应用会在单击按钮时生成并显示图像.

This app produces and displays an image when a button is clicked.

图像是用 matplotlib savefig("displayimage.png") 在与我的应用程序 .py 文件相同的文件夹中生成的.

The image is produced with matplotlib savefig("displayimage.png") in same folder as my app .py file.

第一次按下按钮时,它显示的图像很好,但是当第二次按下时,新图像与旧图像重叠.

It shows the image fine when the button is pressed first time, but when it is pressed second time the new image overlaps the old one.

我尝试通过 os.remove("displayimage.png") 从文件夹中删除现有图像,但这根本没有帮助.

I tried to remove the existing image from the folder by os.remove("displayimage.png"), but this doesnt help at all.

你知道为什么它不只是覆盖旧图像而不是重叠吗?

Do you know why it doesnt just overwrites the old image instead of overlap?

ps.我试过另存为 .jpg 但结果相同.

ps. i have tried saving as .jpg but same result.

提前致谢.代码:

# make a square figure and axes
figure(1, figsize=(6, 6))
ax = axes([0.1, 0.1, 0.8, 0.8])

# The slices will be ordered and plotted counter-clockwise.
labels = words
fracs = percent
colors = ('yellowgreen', 'gold', 'lightskyblue', 'lightcoral', 'blue', 'yellow', 'cyan', 'pink',
          'purple', 'green', 'magenta', 'orange')

pie(fracs, labels=labels, colors=colors,
    autopct='%.1f%%', shadow=True, startangle=90)

title("Most used words", fontsize=20)

savefig('senalyzed_piechart.png',dpi=80)

推荐答案

这是因为您没有清除缓冲区.使用 plot.clf() 方法.就可以了.

its because you didn't clear the buffer. use the the plot.clf() method.and it will be alright.

这篇关于为什么 Matplotlib savefig 图像重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆