gpt4 book ai didi

python - 为什么 Matplotlib savefig 图像重叠?

转载 作者:太空狗 更新时间:2023-10-30 00:25:13 35 4
gpt4 key购买 nike

我已经在使用 Tkinter 的 Python 中构建了一个 GUI 应用程序。

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

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

第一次按下按钮时图像显示正常,但第二次按下时新图像与旧图像重叠。

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

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

附言。我尝试另存为 .jpg 但结果相同。

提前致谢。代码:

# 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() 方法。它会好的。

关于python - 为什么 Matplotlib savefig 图像重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20352111/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com