-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraw_emgplot.py
executable file
·87 lines (62 loc) · 1.63 KB
/
raw_emgplot.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
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import mpld3
from datetime import datetime
from matplotlib.ticker import FuncFormatter
fig, ax = plt.subplots()
#x holds time values, y(n) holds data for respective channels
x, y1, y2, y3 = [], [], [], []
#import raw data into a file object
f = open('AB.txt', 'r');
#iterate over file and format raw string data to something matplotlib actually likes
for line in f:
#split each row on white space
row = line.split()
#convert H:M:S.f formatted string to datetime object
xvalue = datetime.strptime(row[0], '%H:%M:%S.%f')
#build our plot array values
x.append(xvalue)
y1.append(row[1])
y2.append(row[2])
y3.append(row[3])
#close file handler
f.close()
#format x ticks to 0 indexed position values instead of arbitrary seconds
def fmtFunc(x, pos):
if(not pos is None):
return pos - 1
#alias our func formatter
xfmt = FuncFormatter(fmtFunc)
#plot raw data for channel 1
plt.subplot(3, 1, 1)
plt.plot(x, y1)
#set x format
plt.gca().xaxis.set_major_formatter(xfmt)
#Set axis labels
plt.ylabel('Voltage')
plt.xlabel('Seconds')
#plot raw data for channel 2
plt.subplot(3, 1, 2)
plt.plot(x, y2)
#set x format
plt.gca().xaxis.set_major_formatter(xfmt)
#Set axis labels
plt.ylabel('Voltage')
plt.xlabel('Seconds')
#plot raw data for channel 3
plt.subplot(3, 1, 3)
plt.plot(x, y3)
#set x format
plt.gca().xaxis.set_major_formatter(xfmt)
#Set axis labels
plt.ylabel('Voltage')
plt.xlabel('Seconds')
#write figure out as html+javascript
html = mpld3.fig_to_html(fig)
f = open('emg.html', 'w');
f.write(html);
f.close()
plt.grid(True)
plt.show()