I have built a GUI app in python which uses Tkinter.
This app produces and displays an image when a button is clicked.
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.
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. i have tried saving as .jpg but same result.
thanks in advance. Code:
# 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)
Faceting. Faceting is one of the methods you can use to avoid overlapping. Seaborn has a function FacetGrid() for faceting. Note that you can see this post for more information.
We can set the dpi value to get a high-quality image. Using the saving() method, we can save the image with format=”png” and dpi=1200. To show the image, use the plt. show() method.
Saving a plot on your disk as an image file Now if you want to save matplotlib figures as image files programmatically, then all you need is matplotlib. pyplot. savefig() function. Simply pass the desired filename (and even location) and the figure will be stored on your disk.
its because you didn't clear the buffer. use the the plot.clf() method.and it will be alright.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With