-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemgPlotter.py
More file actions
87 lines (67 loc) · 2.69 KB
/
emgPlotter.py
File metadata and controls
87 lines (67 loc) · 2.69 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 matplotlib.pyplot as plt
def plot_one_emg(df, y_col, x_col=None, title="Line Plot"):
plt.figure(num=1)
y_data = df[y_col]
if x_col is not None:
x_data = df[x_col]
plt.xlabel(x_col)
else:
x_data = range(len(y_data))
plt.xlabel("Index")
plt.plot(x_data, y_data)
plt.ylabel(y_col)
plt.title(title)
plt.grid(True)
plt.tight_layout()
def plot_four_emg(df, y_cols, channel, x_vals=None, title="Four-Channel EMG Plot"):
if len(y_cols) != 4 or len(channel) != 4:
raise ValueError("Exactly four y-columns and four channel names must be specified.")
colors = [
(57/255, 106/255, 177/255), # blue
(191/255, 191/255, 0/255), # yellow
(62/255, 150/255, 81/255), # green
(204/255, 37/255, 41/255) # red
]
plt.figure(num=2, figsize=(10, 6))
x_data = x_vals if x_vals is not None else range(len(df))
x_label = "Time (s)" if x_vals is not None else "Index"
for i in range(4):
plt.plot(x_data, df[y_cols[i]], label=channel[i], color=colors[i])
plt.xlabel(x_label)
plt.ylabel("Voltage (mV)")
plt.title(title)
plt.legend()
plt.grid(True)
plt.tight_layout()
def plot_four_emg_sub(df, y_cols, channel, x_vals=None, title="Four-Channel EMG Plot"):
if len(y_cols) != 4 or len(channel) != 4:
raise ValueError("Exactly four y-columns and four channel names must be specified.")
colors = [
(57/255, 106/255, 177/255), # blue
(191/255, 191/255, 0/255), # yellow
(62/255, 150/255, 81/255), # green
(204/255, 37/255, 41/255) # red
]
fig, axs = plt.subplots(4, 1, sharex=True, num=3, figsize=(10, 8))
fig.suptitle(title)
x_data = x_vals if x_vals is not None else range(len(df))
x_label = "Time (s)" if x_vals is not None else "Index"
for i, (ax, y_col, ch_label) in enumerate(zip(axs, y_cols, channel)):
ax.plot(x_data, df[y_col], color=colors[i], label=ch_label)
ax.set_ylabel("Voltage (mV)")
ax.grid(True)
ax.legend(loc="upper right")
axs[-1].set_xlabel(x_label)
plt.tight_layout(rect=[0, 0, 1, 0.96])
def plot_data(df, y_cols, x_vals=None, title="Data Plots", figNum=1):
colNum = len(df.columns)
rowNum = len(df)
fig, axs = plt.subplots(colNum, 1, sharex=True, num=figNum, figsize=(10, 8))
fig.suptitle(title)
x_data = x_vals if x_vals is not None else range(rowNum)
x_label = "Time (s)" if x_vals is not None else "Index"
for i, (ax, y_col) in enumerate(zip(axs, y_cols)):
ax.plot(x_data, df[y_col])
ax.grid(True)
axs[-1].set_xlabel(x_label)
plt.tight_layout(rect=[0, 0, 1, 0.96])