@@ -403,8 +403,8 @@ def plot_emg(ts=None,
403403 sampling_rate = None ,
404404 raw = None ,
405405 filtered = None ,
406- processed = None ,
407406 onsets = None ,
407+ processed = None ,
408408 path = None ,
409409 show = False ):
410410 """Create a summary plot from the output of signals.emg.emg.
@@ -419,10 +419,10 @@ def plot_emg(ts=None,
419419 Raw EMG signal.
420420 filtered : array
421421 Filtered EMG signal.
422- processed : array
423- Processed EMG signal according to the chosen onset detector.
424422 onsets : array
425423 Indices of EMG pulse onsets.
424+ processed : array, optional
425+ Processed EMG signal according to the chosen onset detector.
426426 path : str, optional
427427 If provided, the plot will be saved to the specified file.
428428 show : bool, optional
@@ -433,18 +433,34 @@ def plot_emg(ts=None,
433433 fig = plt .figure ()
434434 fig .suptitle ('EMG Summary' )
435435
436- # raw signal
437- ax1 = fig .add_subplot (311 )
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 )
438455
456+ # raw signal
439457 ax1 .plot (ts , raw , linewidth = MAJOR_LW , label = 'Raw' )
440458
441459 ax1 .set_ylabel ('Amplitude' )
442460 ax1 .legend ()
443461 ax1 .grid ()
444462
445463 # filtered signal with onsets
446- ax2 = fig .add_subplot (312 , sharex = ax1 )
447-
448464 ymin = np .min (filtered )
449465 ymax = np .max (filtered )
450466 alpha = 0.1 * (ymax - ymin )
@@ -462,14 +478,6 @@ def plot_emg(ts=None,
462478 ax2 .legend ()
463479 ax2 .grid ()
464480
465- # processed signal
466- ax3 = fig .add_subplot (313 )
467- ax3 .plot (np .arange (len (processed ))/ sampling_rate , processed , linewidth = MAJOR_LW , label = 'Processed' )
468- ax3 .set_xlabel ('Time (s)' )
469- ax3 .set_ylabel ('Amplitude' )
470- ax3 .legend ()
471- ax3 .grid ()
472-
473481 # make layout tight
474482 fig .tight_layout ()
475483
0 commit comments