Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit da02d97

Browse files
committed
Merge branch 'pr/17'
2 parents e51fcd2 + 1709dad commit da02d97

File tree

3 files changed

+64906
-6
lines changed

3 files changed

+64906
-6
lines changed

biosppy/plotting.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,11 @@ def plot_eda(ts=None,
400400

401401

402402
def plot_emg(ts=None,
403+
sampling_rate=None,
403404
raw=None,
404405
filtered=None,
405406
onsets=None,
407+
processed=None,
406408
path=None,
407409
show=False):
408410
"""Create a summary plot from the output of signals.emg.emg.
@@ -411,12 +413,16 @@ def plot_emg(ts=None,
411413
----------
412414
ts : array
413415
Signal time axis reference (seconds).
416+
sampling_rate : int, float
417+
Sampling frequency (Hz).
414418
raw : array
415419
Raw EMG signal.
416420
filtered : array
417421
Filtered EMG signal.
418422
onsets : array
419423
Indices of EMG pulse onsets.
424+
processed : array, optional
425+
Processed EMG signal according to the chosen onset detector.
420426
path : str, optional
421427
If provided, the plot will be saved to the specified file.
422428
show : bool, optional
@@ -427,18 +433,34 @@ def plot_emg(ts=None,
427433
fig = plt.figure()
428434
fig.suptitle('EMG Summary')
429435

430-
# raw signal
431-
ax1 = fig.add_subplot(211)
436+
if processed is not None:
437+
ax1 = fig.add_subplot(311)
438+
ax2 = fig.add_subplot(312, sharex=ax1)
439+
ax3 = fig.add_subplot(313)
440+
441+
# processed signal
442+
L = len(processed)
443+
T = (L - 1) / sampling_rate
444+
ts_processed = np.linspace(0, T, L, endpoint=False)
445+
ax3.plot(ts_processed, processed,
446+
linewidth=MAJOR_LW,
447+
label='Processed')
448+
ax3.set_xlabel('Time (s)')
449+
ax3.set_ylabel('Amplitude')
450+
ax3.legend()
451+
ax3.grid()
452+
else:
453+
ax1 = fig.add_subplot(211)
454+
ax2 = fig.add_subplot(212, sharex=ax1)
432455

456+
# raw signal
433457
ax1.plot(ts, raw, linewidth=MAJOR_LW, label='Raw')
434458

435459
ax1.set_ylabel('Amplitude')
436460
ax1.legend()
437461
ax1.grid()
438462

439463
# filtered signal with onsets
440-
ax2 = fig.add_subplot(212, sharex=ax1)
441-
442464
ymin = np.min(filtered)
443465
ymax = np.max(filtered)
444466
alpha = 0.1 * (ymax - ymin)

0 commit comments

Comments
 (0)