plot

The plot subpackage contains tools for plotting signals and annotations.

wfdb.plot.plot_items(signal=None, ann_samp=None, ann_sym=None, fs=None, time_units='samples', sig_name=None, sig_units=None, ylabel=None, title=None, sig_style=[''], ann_style=['r*'], ecg_grids=[], figsize=None, return_fig=False)

Subplot individual channels of signals and/or annotations.

signal : 1d or 2d numpy array, optional
The uniformly sampled signal to be plotted. If signal.ndim is 1, it is assumed to be a one channel signal. If it is 2, axes 0 and 1, must represent time and channel number respectively.
ann_samp: list, optional

A list of annotation locations to plot, with each list item corresponding to a different channel. List items may be:

  • 1d numpy array, with values representing sample indices. Empty arrays are skipped.
  • list, with values representing sample indices. Empty lists are skipped.
  • None. For channels in which nothing is to be plotted.

If signal is defined, the annotation locations will be overlaid on the signals, with the list index corresponding to the signal channel. The length of annotation does not have to match the number of channels of signal.

ann_sym: list, optional
A list of annotation symbols to plot, with each list item corresponding to a different channel. List items should be lists of strings. The symbols are plotted over the corresponding ann_samp index locations.
fs : int or float, optional
The sampling frequency of the signals and/or annotations. Used to calculate time intervals if time_units is not ‘samples’. Also required for plotting ecg grids.
time_units : str, optional
The x axis unit. Allowed options are: ‘samples’, ‘seconds’, ‘minutes’, and ‘hours’.
sig_name : list, optional
A list of strings specifying the signal names. Used with sig_units to form y labels, if ylabel is not set.
sig_units : list, optional
A list of strings specifying the units of each signal channel. Used with sig_name to form y labels, if ylabel is not set. This parameter is required for plotting ecg grids.
ylabel : list, optional
A list of strings specifying the final y labels. If this option is present, sig_name and sig_units will not be used for labels.
title : str, optional
The title of the graph.
sig_style : list, optional
A list of strings, specifying the style of the matplotlib plot for each signal channel. The list length should match the number of signal channels. If the list has a length of 1, the style will be used for all channels.
ann_style : list, optional
A list of strings, specifying the style of the matplotlib plot for each annotation channel. If the list has a length of 1, the style will be used for all channels.
ecg_grids : list, optional
A list of integers specifying channels in which to plot ecg grids. May also be set to ‘all’ for all channels. Major grids at 0.5mV, and minor grids at 0.125mV. All channels to be plotted with grids must have sig_units equal to ‘uV’, ‘mV’, or ‘V’.
figsize : tuple, optional
Tuple pair specifying the width, and height of the figure. It is the ‘figsize’ argument passed into matplotlib.pyplot’s figure function.
return_fig : bool, optional
Whether the figure is to be returned as an output argument.
figure : matplotlib figure, optional
The matplotlib figure generated. Only returned if the ‘return_fig’ parameter is set to True.
>>> record = wfdb.rdrecord('sample-data/100', sampto=3000)
>>> ann = wfdb.rdann('sample-data/100', 'atr', sampto=3000)
>>> wfdb.plot_items(signal=record.p_signal,
                    annotation=[ann.sample, ann.sample],
                    title='MIT-BIH Record 100', time_units='seconds',
                    figsize=(10,4), ecg_grids='all')
wfdb.plot.plot_wfdb(record=None, annotation=None, plot_sym=False, time_units='samples', title=None, sig_style=[''], ann_style=['r*'], ecg_grids=[], figsize=None, return_fig=False)

Subplot individual channels of a wfdb record and/or annotation.

This function implements the base functionality of the plot_items function, while allowing direct input of wfdb objects.

If the record object is input, the function will extract from it:
  • signal values, from the p_signal (priority) or d_signal attribute
  • sampling frequency, from the fs attribute
  • signal names, from the sig_name attribute
  • signal units, from the units attribute
If the annotation object is input, the function will extract from it:
  • sample locations, from the sample attribute
  • symbols, from the symbol attribute
  • the annotation channels, from the chan attribute
  • the sampling frequency, from the fs attribute if present, and if fs was not already extracted from the record argument.
record : wfdb Record, optional
The Record object to be plotted
annotation : wfdb Annotation, optional
The Annotation object to be plotted
plot_sym : bool, optional
Whether to plot the annotation symbols on the graph.
time_units : str, optional
The x axis unit. Allowed options are: ‘samples’, ‘seconds’, ‘minutes’, and ‘hours’.
title : str, optional
The title of the graph.
sig_style : list, optional
A list of strings, specifying the style of the matplotlib plot for each signal channel. The list length should match the number of signal channels. If the list has a length of 1, the style will be used for all channels.
ann_style : list, optional
A list of strings, specifying the style of the matplotlib plot for each annotation channel. The list length should match the number of annotation channels. If the list has a length of 1, the style will be used for all channels.
ecg_grids : list, optional
A list of integers specifying channels in which to plot ecg grids. May also be set to ‘all’ for all channels. Major grids at 0.5mV, and minor grids at 0.125mV. All channels to be plotted with grids must have sig_units equal to ‘uV’, ‘mV’, or ‘V’.
figsize : tuple, optional
Tuple pair specifying the width, and height of the figure. It is the ‘figsize’ argument passed into matplotlib.pyplot’s figure function.
return_fig : bool, optional
Whether the figure is to be returned as an output argument.
figure : matplotlib figure, optional
The matplotlib figure generated. Only returned if the ‘return_fig’ option is set to True.
>>> record = wfdb.rdrecord('sample-data/100', sampto=3000)
>>> annotation = wfdb.rdann('sample-data/100', 'atr', sampto=3000)
>>> wfdb.plot_wfdb(record=record, annotation=annotation, plot_sym=True
                   time_units='seconds', title='MIT-BIH Record 100',
                   figsize=(10,4), ecg_grids='all')
wfdb.plot.plot_all_records(directory='')

Plot all wfdb records in a directory (by finding header files), one at a time, until the ‘enter’ key is pressed.

directory : str, optional
The directory in which to search for WFDB records. Defaults to current working directory.