forked from NeuroNetMem/PythonPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignal_plot.pyx
More file actions
87 lines (73 loc) · 2.43 KB
/
Copy pathsignal_plot.pyx
File metadata and controls
87 lines (73 loc) · 2.43 KB
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
import sys
import numpy as np
cimport numpy as np
from cython cimport view
import matplotlib
# matplotlib.use('CocoaAgg')
matplotlib.use('QT4agg')
import matplotlib.pyplot as plt
isDebug = False
class SimplePlotter(object):
def __init__(self):
print ("init")
#define variables
self.y = np.empty([0,], dtype = np.float32)
self.chan_in = 2
self.plotting_interval = 250. # in ms
self.frame_count = 0
self.frame_max = 0
self.sampling_rate = 0.
self.ax = None
self.hl = None
self.figure = None
self.n_samples = 0
def startup(self, sr):
print ("startup")
#initialize plot
self.sampling_rate = sr
self.figure, self.ax = plt.subplots()
print ("figure: ", self.figure)
self.hl, = self.ax.plot([],[])
self.ax.set_autoscaley_on(True)
self.ax.margins(y=0.1)
self.ax.set_xlim(0., 4. * np.pi)
# plt.ion()
plt.show(block=False)
self.hl.set_ydata(np.zeros(100,))
self.hl.set_xdata(np.linspace(0, 4 *np.pi, 100))
self.ax.relim()
self.ax.autoscale_view(True,True,True)
self.figure.canvas.draw()
self.figure.canvas.flush_events()
def plugin_name(self):
return "SimplePlotter"
def is_ready(self):
return 1
def param_config(self):
return ()
def bufferfunction(self, n_arr):
# setting up frame dependent parameters
self.n_samples = int(n_arr.shape[1])
frame_time = 1000. * self.n_samples / self.sampling_rate
self.frame_max = int(self.plotting_interval / frame_time)
#increment the buffer
self.y = np.append(self.y, n_arr[self.chan_in-1, :])
self.frame_count += 1
if self.frame_count == self.frame_max:
#update the plot
print ("updating plot")
x = np.arange(len(self.y), dtype=np.float32) * 1000. / self.sampling_rate
print( x[-1])
self.hl.set_ydata(self.y)
self.hl.set_xdata(x)
self.ax.set_xlim(0., self.plotting_interval)
self.ax.relim()
self.ax.autoscale_view(True,True,True)
self.figure.canvas.draw()
# self.figure.canvas.flush_events()
self.frame_count = 0
self.y = np.empty([0,], dtype = np.float32)
events = []
return events
pluginOp = SimplePlotter()
include "../plugin.pyx"