GUI Progress: Inline animated graphs

This commit is contained in:
LSaldyt
2017-10-21 10:41:46 -07:00
parent aafb0de433
commit 71c7b34f63
5 changed files with 87117 additions and 91820 deletions

178756
copycat.log

File diff suppressed because it is too large Load Diff

60
copycat/figureframe.py Normal file
View File

@ -0,0 +1,60 @@
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import tkinter as tk
import tkinter.ttk as ttk
import time
LARGE_FONT = ('Verdana', 14)
class FigureFrame(tk.Frame):
def __init__(self, parent, figure, title):
self.figure = figure
tk.Frame.__init__(self, parent)
label = tk.Label(self, text=title, font=LARGE_FONT)
label.pack(pady=10,padx=10)
self.canvas = FigureCanvasTkAgg(self.figure, self)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2TkAgg(self.canvas, self)
toolbar.update()
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
def update(self, figure):
self.canvas = FigureCanvasTkAgg(self.figure, self)
self.canvas.show()
if __name__ == '__main__':
root = tk.Tk()
x = [1,2,3,4]
y = [2,3,4,5]
f = Figure(figsize=(5,5), dpi=100)
a = f.add_subplot(111)
a.plot(x, y)
figure = FigureFrame(root, f, 'Lines')
figure.pack()
i = 0
while True:
root.update()
root.update_idletasks()
time.sleep(1)
i += 1
x += [i]
y += [i**2]
print(x, y)
f = Figure(figsize=(5,5), dpi=100)
a = f.add_subplot(111)
a.plot(x, y)
#a.clear()
#a.plot(x, y)
figure = FigureFrame(root, f, 'Lines')

4
copycat/sampleText.txt Normal file
View File

@ -0,0 +1,4 @@
1,2
3,4
7,7
100,100

60
copycat/status.py Normal file
View File

@ -0,0 +1,60 @@
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import tkinter as tk
import tkinter.ttk as ttk
import time
import matplotlib.animation as animation
import matplotlib.pyplot as plt
plt.style.use('dark_background')
LARGE_FONT = ('Verdana', 20)
class StatusFrame(tk.Frame):
def __init__(self, parent, status, title):
self.status = status
tk.Frame.__init__(self, parent)
label = tk.Label(self, text=title, font=LARGE_FONT)
label.pack(pady=10,padx=10)
canvas = FigureCanvasTkAgg(status.figure, self)
canvas.show()
canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2TkAgg(canvas, self)
toolbar.update()
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
self.animation = animation.FuncAnimation(status.figure, lambda i : status.update_plots(i), interval=1000)
class Status(object):
def __init__(self):
self.figure = Figure(figsize=(5,5), dpi=100)
self.subplot = self.figure.add_subplot(111)
self.x = []
self.y = []
def update_plots(self, i):
self.subplot.clear()
self.subplot.plot(self.x, self.y)
if __name__ == '__main__':
app = tk.Tk()
status = Status()
sframe = StatusFrame(app, status, 'x**2')
sframe.pack()
i = 0
while True:
app.update()
app.update_idletasks()
time.sleep(.01)
i += 1
status.x += [i]
status.y += [i**2]

57
copycat/test.py Normal file
View File

@ -0,0 +1,57 @@
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import tkinter as tk
import tkinter.ttk as ttk
import time
import matplotlib.animation as animation
import matplotlib.pyplot as plt
plt.style.use('dark_background')
LARGE_FONT = ('Verdana', 20)
f = Figure(figsize=(5,5), dpi=100)
a = f.add_subplot(111)
def animate(i):
print(i)
pullData = open("sampleText.txt","r").read()
dataList = pullData.split('\n')
xList = []
yList = []
for eachLine in dataList:
if len(eachLine) > 1:
x, y = eachLine.split(',')
xList.append(int(x))
yList.append(int(y))
a.clear()
a.plot(xList, yList)
class test(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Graph Page!", font=LARGE_FONT)
label.pack(pady=10,padx=10)
canvas = FigureCanvasTkAgg(f, self)
canvas.show()
canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2TkAgg(canvas, self)
toolbar.update()
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
app = tk.Tk()
test = test(app)
test.grid()
ani = animation.FuncAnimation(f, animate, interval=1000)
app.mainloop()