Skip to content

Commit e2bd679

Browse files
committed
add annstyle option to plotrec
1 parent 08d594a commit e2bd679

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ Input Arguments:
343343
- ``annotation`` (default=None): A list of Annotation objects or numpy arrays. The locations of the Annotation objects' 'annsamp' attribute, or the locations of the numpy arrays' values, will be overlaid on the signals. The list index of the annotation item corresponds to the signal channel that each annotation set will be plotted on. For channels without annotations to plot, put None in the list. This argument may also be just an Annotation object or numpy array, which will be plotted over channel 0.
344344
- ``timeunits`` (default='samples'): String specifying the x axis unit. Allowed options are: 'samples', 'seconds', 'minutes', and 'hours'.
345345
- ``sigstyle`` (default=''): String, or list of strings, specifying the styling of the matplotlib plot for the signals. If 'sigstyle' is a string, each channel will have the same style. If it is a list, each channel's style will correspond to the list element. ie. sigtype=['r','b','k'].
346+
- ``annstyle`` (default='r*'): String, or list of strings, specifying the styling of the matplotlib plot for the annotations. If 'annstyle' is a string, each channel will have the same style. If it is a list, each channel's style will correspond to the list element.
346347
- ``figsize`` (default=None): Tuple pair specifying the width, and height of the figure. Same as the 'figsize' argument passed into matplotlib.pyplot's figure() function.
347348
- ``returnfig`` (default=False): Specifies whether the figure is to be returned as an output argument
348349
- ``ecggrids`` (default=[]): List of integers specifying channels in which to plot ecg grids. May be set to [] for no channels, or 'all' for all channels. Major grids at 0.5mV, and minor grids at 0.125mV. All channels to be plotted with grids must have units equal to 'uV', 'mV', or 'V'.

wfdb/plot/plots.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
# Plot a WFDB Record's signals
99
# Optionally, overlay annotation locations
10-
def plotrec(record=None, title = None, annotation = None, timeunits='samples', sigstyle='', figsize=None, returnfig = False, ecggrids=[]):
10+
def plotrec(record=None, title = None, annotation = None, timeunits='samples', sigstyle='', annstyle='r*', figsize=None, returnfig = False, ecggrids=[]):
1111
""" Subplot and label each channel of a WFDB Record.
1212
Optionally, subplot annotation locations over selected channels.
1313
1414
Usage:
1515
plotrec(record=None, title = None, annotation = None, timeunits='samples', sigstyle='',
16-
figsize=None, returnfig = False, ecggrids=[])
16+
annstyle='r*', figsize=None, returnfig = False, ecggrids=[])
1717
1818
Input arguments:
1919
- record (required): A wfdb Record object. The p_signals attribute will be plotted.
@@ -25,9 +25,12 @@ def plotrec(record=None, title = None, annotation = None, timeunits='samples', s
2525
an Annotation object or numpy array, which will be plotted over channel 0.
2626
- timeunits (default='samples'): String specifying the x axis unit.
2727
Allowed options are: 'samples', 'seconds', 'minutes', and 'hours'.
28-
- sigstyle (default=''): String, or list of strings, specifying the styling of the matplotlib plot for the signals.
28+
- sigstyle (default='r*'): String, or list of strings, specifying the styling of the matplotlib plot for the signals.
2929
If 'sigstyle' is a string, each channel will have the same style. If it is a list, each channel's style will
3030
correspond to the list element. ie. sigtype=['r','b','k']
31+
- annstyle (default='r*'): String, or list of strings, specifying the styling of the matplotlib plot for the annotations.
32+
If 'annstyle' is a string, each channel will have the same style. If it is a list, each channel's style will
33+
correspond to the list element.
3134
- figsize (default=None): Tuple pair specifying the width, and height of the figure. Same as the 'figsize' argument
3235
passed into matplotlib.pyplot's figure() function.
3336
- returnfig (default=False): Specifies whether the figure is to be returned as an output argument
@@ -49,7 +52,7 @@ def plotrec(record=None, title = None, annotation = None, timeunits='samples', s
4952

5053
# Check the validity of items used to make the plot
5154
# Return the x axis time values to plot for the record (and annotation if any)
52-
t, tann, annplot = checkplotitems(record, title, annotation, timeunits, sigstyle)
55+
t, tann, annplot = checkplotitems(record, title, annotation, timeunits, sigstyle, annstyle)
5356

5457
siglen, nsig = record.p_signals.shape
5558

@@ -59,6 +62,11 @@ def plotrec(record=None, title = None, annotation = None, timeunits='samples', s
5962
else:
6063
if len(sigstyle) < record.nsig:
6164
sigstyle = sigstyle+['']*(record.nsig-len(sigstyle))
65+
if type(annstyle) == str:
66+
annstyle = [annstyle]*record.nsig
67+
else:
68+
if len(annstyle) < record.nsig:
69+
annstyle = annstyle+['r*']*(record.nsig-len(annstyle))
6270

6371
# Expand ecg grid channels
6472
if ecggrids == 'all':
@@ -77,7 +85,7 @@ def plotrec(record=None, title = None, annotation = None, timeunits='samples', s
7785

7886
# Plot annotation if specified
7987
if annplot[ch] is not None:
80-
ax.plot(tann[ch], record.p_signals[annplot[ch], ch], 'r+')
88+
ax.plot(tann[ch], record.p_signals[annplot[ch], ch], annstyle[ch])
8189

8290
# Axis Labels
8391
if timeunits == 'samples':
@@ -170,8 +178,8 @@ def calc_ecg_grids(minsig, maxsig, units, fs, maxt, timeunits):
170178
return (major_ticks_x, minor_ticks_x, major_ticks_y, minor_ticks_y)
171179

172180
# Check the validity of items used to make the plot
173-
# Return the x axis time values to plot for the record (and annotation if any)
174-
def checkplotitems(record, title, annotation, timeunits, sigstyle):
181+
# Return the x axis time values to plot for the record (and time and values for annotation if any)
182+
def checkplotitems(record, title, annotation, timeunits, sigstyle, annstyle):
175183

176184
# signals
177185
if type(record) != records.Record:
@@ -229,6 +237,15 @@ def checkplotitems(record, title, annotation, timeunits, sigstyle):
229237
else:
230238
raise TypeError("The 'sigstyle' field must be a string or a list of strings")
231239

240+
# annotation plot style
241+
if type(annstyle) == str:
242+
pass
243+
elif type(annstyle) == list:
244+
if len(annstyle) > record.nsig:
245+
raise ValueError("The 'annstyle' list cannot have more elements than the number of record channels")
246+
else:
247+
raise TypeError("The 'annstyle' field must be a string or a list of strings")
248+
232249

233250
# Annotations if any
234251
if annotation is not None:

0 commit comments

Comments
 (0)