Skip to content

Commit 317c427

Browse files
author
Benjamin Moody
committed
plot_annotation: accept non-smooth signal data as input.
When plotting signals, in addition to allowing the signal argument to be a one-dimensional or two-dimensional array, allow it to be a list of one-dimensional arrays (so that each channel can have a different length.) If signal is a 1D or 2D array, convert it to a list of arrays using _expand_channels. This allows the later logic to be simplified.
1 parent da3bce5 commit 317c427

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

wfdb/plot/plot.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,12 @@ def plot_annotation(ann_samp, n_annot, ann_sym, signal, n_sig, fs, time_units,
439439
The number of annotations contained in the dat file.
440440
ann_sym : list
441441
The values of the annotation symbol locations.
442-
signal : ndarray
443-
Tranformed expanded signal into uniform signal.
442+
signal : 1d or 2d numpy array or list
443+
The uniformly sampled signal or signals to be plotted. If signal
444+
is a one-dimensional array, it is assumed to represent a single
445+
channel. If it is a two-dimensional array, axes 0 and 1 must
446+
represent time and channel number respectively. Otherwise it must
447+
be a list of one-dimensional arrays (one for each channel).
444448
n_sig : int
445449
The number of signals contained in the dat file.
446450
fs : float
@@ -469,6 +473,9 @@ def plot_annotation(ann_samp, n_annot, ann_sym, signal, n_sig, fs, time_units,
469473
N/A
470474
471475
"""
476+
# Convert signal to a list if needed
477+
signal = _expand_channels(signal)
478+
472479
# Extend annotation style if necessary
473480
if len(ann_style) == 1:
474481
ann_style = n_annot * ann_style
@@ -508,10 +515,7 @@ def plot_annotation(ann_samp, n_annot, ann_sym, signal, n_sig, fs, time_units,
508515
index = ann_samp[ch]
509516
else:
510517
index = (sfreq / afreq * ann_samp[ch]).astype('int')
511-
if signal.ndim == 1:
512-
y = signal[index]
513-
else:
514-
y = signal[index, ch]
518+
y = signal[ch][index]
515519
else:
516520
y = np.zeros(len(ann_samp[ch]))
517521
except IndexError:

0 commit comments

Comments
 (0)