import matplotlib
matplotlib.use("WXAgg")
from matplotlib import pyplot as plt
import numpy
import threading
import wx
import time
x = []
y = []
fig = plt.figure()
ax = fig.add_subplot(111)
line = ax.plot(x,y)[0]
ax.set_ylim(-1,1)
def update(x, y):
"""put code to update plot or other GUI stuff here"""
x = numpy.array(x)
y = numpy.array(y)
line.set_data(x, y)
fig.canvas.draw()
ax.set_xlim(x.min(), x.max())
class ProcessThread(threading.Thread):
def start(self):
self._running = True
super(ProcessThread, self).start()
def stop(self):
self._running = False
self.join(5.0)
def run(self):
"""Do GPIO stuff here, but don't do GUI stuff"""
t = time.time()
while self._running:
now = time.time()
x.append(now-t)
y.append(numpy.cos(now-t))
wx.CallAfter(update, x , y) #calls update in the GUI thread
time.sleep(0.2)
thd = ProcessThread()
thd.start()
plt.show()
thd.stop()