I am trying to show a graph on the screen that I just plotted using matplotlib on python.
Basically, my program receives a bunch of parameters and then makes a graph, that should be displayed on screen.
Since I am new to tkinter, I made a simple program to see if the code worked:
from tkinter import *
from PIL import ImageTk, Image
root=Tk()
my_img1=ImageTk.PhotoImage(Image.open("plot.png"))
my_label=Label(image=my_img1)
my_label.grid(row=0,column=0,columnspan=3)
mainloop()
This works just fine.
However, when I introduce it into my actual program:
def graficar_fracciones():
lista_de_ERRtotal=()
for i in range(1,50):
agregar=ERR_total(i)
if agregar <0:
lista_de_ERRtotal.append(0)
else:
lista_de_ERRtotal.append(agregar)
plt.figure(figsize=(1.5,1))
plt.plot(lista_de_ERRtotal)
plt.xlabel("Cantidad de fracciones")
plt.ylabel('ERR Total')
plt.savefig('plot.png', dpi=300, bbox_inches='tight')
my_img1=ImageTk.PhotoImage(Image.open("plot.png"))
my_label=Label(image=my_img1)
my_label.grid(row=0,column=0,columnspan=3)
return
This function graphs the plot, then saves it. Then I open that plot and try to show it on screen, but it just shows blank.
Why could this be happening? I have checked some similar posts, but haven’t been able to find an answer.