I am trying to graph a series of data from a text file, but my idea is that this graph only appears when I press a button on a GUI made in tkinter. However, at the moment of pressing the button the graph appears but without the data, that is, it appears in white.
Well, I'll give you my code and I hope you can help me:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from tkinter import *
from tkinter import ttk
class ini():
def __init__(self):
self.fig = plt.figure()
self.ax1 = self.fig.add_subplot(1,1,1)
self.datosy=[]
self.datosx=[]
def animada(self):
datostext = open('datos.txt','r').read()
lines = datostext.split('\n')
for line in lines:
if len(line)>1:
self.x, self.y = line.split(",")
self.datosx.append(self.x)
self.datosy.append(self.y)
self.ax1.clear()
self.ax1.plot(self.datosx,self.datosy)
def fungraf(self):
self.ani = animation.FuncAnimation(self.fig,
self.animada, #serias dudas aca
interval=1000)
plt.show()
h=ini()
raiz=Tk()
raiz.geometry("600x600")
boton=ttk.Button(raiz,text="start",command=h.fungraf)
boton.pack()
raiz.mainloop()