私はPythonにかなり慣れていませんが、tkinterとmatplotlibの初心者です。私は本質的に私が最終的にやりたいことのテストベッドである次のコードを持っています。
#!/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)
これをtkinterに埋め込むにはどうすればよいですか。私は何時間も検索し、多くの提案に出くわしましたが、それらのどれも動的プロットには適用されないようです. このプログラムが使用しているデータを誰かが見たい場合は、次のコードで作成しました。
#!/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)
もちろん、これを正しく理解していないだけかもしれません