I am fairly new to python and a real beginner to tkinter and matplotlib. I have the following code which essentially is a testbed for what I eventually want to do.
#!/usr/bin/env python
import numpy as np
from matplotlib import pyplot as plt
import time
top = 100
plt.ion () # set plot to animated
xdata = []
c = 0
for a in range(0,top):
xdata.append(a)
c+=1
ydata = [ 0 ] * top * 10
ax1 = plt.axes ()
c = 0
myfile = open("rdata.txt", "r")
for myline in myfile:
q = myline
ydata[c] = q
c+=1
c = 0
# Make plot
line, = plt.plot (ydata[0:60])
myfile = open("rdata.txt", "r")
for p in range(0, top * 10):
for myline in myfile:
q = int(myline)
ydata.append (q)
del ydata [ 0 ]
line.set_xdata (np.arange ( len (ydata)))
line.set_ydata (ydata) # update the data
time.sleep(0.01)
plt.draw () # update the plot
# c +=1
file.close(myfile)
How can I embed this in tkinter. I have searched for hours and have come across many suggestions but it seems none of them apply to dynamic plots. If anyone wants to see the data this program is using I created it with the following code.
#!/usr/bin/env python
import random
myfile = open("rdata.txt", "w")
myfile.write("100\n")
myfile.write("0\n")
for x in range(2,100):
q = random.randint(10,90)
myfile.write(str(q))
myfile.write("\n")
file.close(myfile)
Of course it may just be that I am just not understanding this correctly