-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLive graph with Matplotlib.py
152 lines (110 loc) · 4.78 KB
/
Live graph with Matplotlib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#;==========================================
#; Title: Tkinter and Matplotlib Combined
#; Author: @AyemunHossain
#;==========================================
import tkinter as tk
from tkinter import ttk
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import matplotlib.animation as animation
from matplotlib import style
style.use('ggplot')
fig = Figure(figsize=(5, 5), dpi=100)
ax = fig.add_subplot(111)
def animate(i):
data = open("e1.txt","r").read()
split_data = data.split('\n')
x=[]
y=[]
for l in split_data:
try:
b, c = l.split(',')
x.append(int(b))
y.append(int(c))
except:
pass
ax.clear()
ax.plot(x,y)
ax.set_xlabel("X Labels")
ax.set_ylabel("Y Labels")
class Major(tk.Tk):
def __init__(self,*args,**kwargs):
tk.Tk.__init__(self,*args,**kwargs)
tk.Tk.geometry(self, '800x600')
containter = tk.Frame(self)
containter.pack(side="top",fill="both",expand=True)
containter.grid_rowconfigure(0,weight=1)
containter.grid_columnconfigure(0, weight=1)
self.frames={}
for F in (HomePage,PageOne,PageTwo,GraphPage):
frame = F(self,containter)
self.frames[F] = frame
frame.grid(row=0,column=0,sticky='news')
self.show_frames(HomePage)
def show_frames(self,cont):
frame = self.frames[cont]
frame.tkraise()
class HomePage(tk.Frame):
def __init__ (self,parent_class,parent_frame):
tk.Frame.__init__(self,parent_frame)
label1 = tk.Label(self,text="It's Your Home Page!!!")
label1.pack(pady=30)
button1= tk.Button(self,text="Page One",width=10,bg='brown',
fg='white',command=lambda:parent_class.show_frames(PageOne))
button1.pack()
button2= tk.Button(self,text="Page Two",width=10,bg='brown',
fg='white',command=lambda:parent_class.show_frames(PageTwo))
button2.pack()
button3 = tk.Button(self, text="Graph Page", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(GraphPage))
button3.pack()
class PageOne(tk.Frame):
def __init__(self,parent_class,parent_frame):
tk.Frame.__init__(self,parent_frame)
label1 = tk.Label(self, text="It's Your Page One!!!")
label1.pack(pady=30)
button1 = tk.Button(self, text="Home Page", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(HomePage))
button1.pack()
button2 = tk.Button(self, text="Page Two", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(PageTwo))
button2.pack()
button3 = tk.Button(self, text="Grpah Page", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(GraphPage))
button3.pack()
class PageTwo(tk.Frame):
def __init__(self,parent_class,parent_frame):
tk.Frame.__init__(self,parent_frame)
label1 = tk.Label(self, text="It's Your Page Two!!!")
label1.pack(pady=30)
button1 = tk.Button(self, text="Home Page", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(HomePage))
button1.pack()
button2 = tk.Button(self, text="Page One", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(PageOne))
button2.pack()
button3 = tk.Button(self, text="Graph Page", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(GraphPage))
button3.pack()
class GraphPage(tk.Frame):
def __init__(self,parent_class,parent_frame):
tk.Frame.__init__(self,parent_frame)
label1 = tk.Label(self, text="Graph Page!!!")
label1.pack(pady=30)
button1 = tk.Button(self, text="Home Page", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(HomePage))
button1.pack()
button2 = tk.Button(self, text="Page One", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(PageOne))
button2.pack()
button3 = tk.Button(self, text="Page Two", width=10, bg='brown',
fg='white', command=lambda: parent_class.show_frames(PageTwo))
button3.pack()
canvas = FigureCanvasTkAgg(fig,self)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP,fill = tk.BOTH,expand= True)
app=Major()
ani = animation.FuncAnimation(fig,animate)
app.mainloop()