Skip to content

Commit e26ebd0

Browse files
committed
add extra ylabels for plot_items when annotation channels don't match signal channels
1 parent 5e6d787 commit e26ebd0

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

wfdb/plot/plot.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ def label_figure(axes, n_subplots, time_units, sig_name, sig_units, ylabel,
315315

316316
ylabel = ['/'.join(pair) for pair in zip(sig_name, sig_units)]
317317

318+
# If there are annotations with channels outside of signal range
319+
# put placeholders
320+
n_missing_labels = n_subplots - len(ylabel)
321+
if n_missing_labels:
322+
ylabel = ylabel + ['ch_%d/NU' % i for i in range(len(ylabel),
323+
n_subplots)]
324+
318325
for ch in range(n_subplots):
319326
axes[ch].set_ylabel(ylabel[ch])
320327

@@ -353,14 +360,15 @@ def plot_wfdb(record=None, annotation=None, plot_sym=False,
353360
plot_sym : bool, optional
354361
Whether to plot the annotation symbols on the graph.
355362
time_units : str, optional
356-
The x axis unit. Allowed options are: 'samples', 'seconds', 'minutes',
357-
and 'hours'.
363+
The x axis unit. Allowed options are: 'samples', 'seconds',
364+
'minutes', and 'hours'.
358365
title : str, optional
359366
The title of the graph.
360367
sig_style : list, optional
361-
A list of strings, specifying the style of the matplotlib plot for each
362-
signal channel. If the list has a length of 1, the style will be used
363-
for all channels.
368+
A list of strings, specifying the style of the matplotlib plot
369+
for each signal channel. The list length should match the number
370+
of signal channels. If the list has a length of 1, the style
371+
will be used for all channels.
364372
ann_style : list, optional
365373
A list of strings, specifying the style of the matplotlib plot for each
366374
annotation channel. If the list has a length of 1, the style will be
@@ -427,23 +435,17 @@ def get_wfdb_plot_items(record, annotation, plot_sym):
427435

428436
# Get annotation attributes
429437
if annotation:
438+
# Note: There may be instances in which the annotation `chan`
439+
# attribute has non-overlapping channels with the signal.
440+
# In this case, omit empty middle channels.
441+
430442
# Get channels
431443
all_chans = set(annotation.chan)
432444

433445
n_chans = max(all_chans) + 1
434446

435-
# Just one channel. Place content in one list index.
436-
# if len(all_chans) == 1:
437-
# ann_samp = annotation.chan[0]*[None] + [annotation.sample]
438-
# if plot_sym:
439-
# ann_sym = annotation.chan[0]*[None] + [annotation.symbol]
440-
# else:
441-
# ann_sym = None
442-
# # Split annotations by channel
443-
# else:
444-
445447
# Indices for each channel
446-
chan_inds = n_chans * [np.empty(0)]
448+
chan_inds = n_chans * [np.empty(0, dtype='int')]
447449

448450
for chan in all_chans:
449451
chan_inds[chan] = np.where(annotation.chan == chan)[0]

0 commit comments

Comments
 (0)