forked from BarkleyUS/mindwave-python
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPlotter.py
60 lines (46 loc) · 1.72 KB
/
Plotter.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
import matplotlib.pyplot as plt
class Plotter:
def __init__(self,rangeval,minval,maxval):
# You probably won't need this if you're embedding things in a tkinter plot...
import matplotlib.pyplot as plt
plt.ion()
self.x = []
self.y = []
self.z = []
self.w = []
self.fig = plt.figure()
self.ax = self.fig.add_subplot(111)
self.line1, = self.ax.plot(self.x,'r', label='X') # Returns a tuple of line objects, thus the comma
self.line2, = self.ax.plot(self.y,'g', label='Y')
self.line3, = self.ax.plot(self.z,'b', label='Z')
self.line4, = self.ax.plot(self.w,'y', label='W')
self.rangeval = rangeval
self.ax.axis([0, rangeval, minval, maxval])
self.plcounter = 0
self.plotx = []
def plotdata(self,new_values):
# is a valid message struct
#print (new_values)
self.x.append( float(new_values[0]))
self.y.append( float(new_values[1]))
self.z.append( float(new_values[2]))
self.w.append( float(new_values[3]))
self.plotx.append( self.plcounter )
self.line1.set_ydata(self.x)
self.line2.set_ydata(self.y)
self.line3.set_ydata(self.z)
self.line4.set_ydata(self.w)
self.line1.set_xdata(self.plotx)
self.line2.set_xdata(self.plotx)
self.line3.set_xdata(self.plotx)
self.line4.set_xdata(self.plotx)
self.fig.canvas.draw()
plt.pause(0.0001)
self.plcounter = self.plcounter+1
if self.plcounter > self.rangeval:
self.plcounter = 0
self.plotx[:] = []
self.x[:] = []
self.y[:] = []
self.z[:] = []
self.w[:] = []