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
|
import matplotlib.animation as anim
import matplotlib.pyplot as plt
import matplotlib
import thread
import time
from Tkinter import *
APP = Tk()
def centrefenetre(fen):
fen.withdraw()
fen.update_idletasks()
x = (1366 - fen.winfo_reqwidth()) / 2
y = (678 - fen.winfo_reqheight()) / 2
fen.geometry("+%d+%d" % (x,y))
fen.deiconify()
class Interface(Frame):
#Fenetre principale d'affichage
def __init__(self, parent):
global APP
Frame.__init__(self, parent)
self.parent = parent
centrefenetre(APP)
APP.resizable(width = False, height = False)
self.grid()
self.tab = []
Button(self, text = "Graphique", command = self.callAnimation).grid()
thread.start_new_thread(self.capture, ())
def capture(self):
cpt = 4.5
while True:
cpt += 0.1
self.tab += [cpt]
time.sleep(1.5)
def init(self):
tabx = [x * 1.5 for x in range(len(self.tab))]
self.ax.set_xlim(0, 1.5 * len(self.tab))
self.line.set_data(tabx, self.tab)
return self.line,
def updateX(self, i):
tabx = [x * 1.5 for x in range(len(self.tab))]
self.ax.set_xlim(0, 1.5 * len(self.tab))
self.line.set_data(tabx, self.tab)
return self.line,
def callAnimation(self):
#For drawing
self.fig = plt.figure()
self.ax = self.fig.add_subplot(111)
self.line = matplotlib.lines.Line2D([0], [0])
self.ax.add_line(self.line)
plt.grid(True)
self.ax.set_ylabel("pH")
self.ax.set_xlabel("Temps")
temp = [4 + x/2. for x in range(14)]
self.ax.set_yticks(temp)
self.ax.set_ylim(4,10)
self.myanim = anim.FuncAnimation(self.fig, self.updateX, init_func = self.init,\
frames = 200, interval = 1500)
plt.show()
def main():
interface = Interface(APP)
APP.mainloop()
if __name__ == '__main__':
main() |
Partager