plot

The plot subpackage contains tools for plotting signals and annotations.

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.

directorystr, optional

The directory in which to search for WFDB records. Defaults to current working directory.

N/A

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

Subplot individual channels of signals and/or annotations.

signal1d or 2d numpy array or list, optional

The signal or signals to be plotted. If signal is a one-dimensional array, it is assumed to represent a single channel. If it is a two-dimensional array, axes 0 and 1 must represent time and channel number respectively. Otherwise it must be a list of one-dimensional arrays (one for each channel).

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.

fsint, 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_unitsstr, optional

The x axis unit. Allowed options are: ‘samples’, ‘seconds’, ‘minutes’, and ‘hours’.

sig_namelist, optional

A list of strings specifying the signal names. Used with sig_units to form y labels, if ylabel is not set.

sig_unitslist, 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.

xlabellist, optional

A list of strings specifying the final x labels to be used. If this option is present, no ‘time/’time_units is used.

ylabellist, 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.

titlestr, optional

The title of the graph.

sig_stylelist, 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_stylelist, 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_gridslist, 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’.

sharex, shareybool, optional

Controls sharing of properties among x (sharex) or y (sharey) axes. If True: x- or y-axis will be shared among all subplots. If False, each subplot x- or y-axis will be independent.

figsizetuple, optional

Tuple pair specifying the width, and height of the figure. It is the ‘figsize’ argument passed into matplotlib.pyplot’s figure function.

return_figbool, optional

Whether the figure is to be returned as an output argument.

sampling_freqnumber or sequence, optional

The sampling frequency or frequencies of the signals. If this is a list, it must have the same length as the number of channels. If unspecified, defaults to fs.

ann_freqnumber or sequence, optional

The sampling frequency or frequencies of the annotations. If this is a list, it must have the same length as ann_samp. If unspecified, defaults to fs.

figmatplotlib figure, optional

The matplotlib figure generated. Only returned if the ‘return_fig’ or ‘return_fig_axes’ parameter is set to True.

axesmatplotlib axes, optional

The matplotlib axes generated. Only returned if the ‘return_fig_axes’ 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,
                    ann_samp=[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='seconds', title=None, sig_style=[''], ann_style=['r*'], ecg_grids=[], figsize=None, return_fig=False, sharex='auto')

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 e_p_signal, e_d_signal, p_signal, or d_signal attribute (in that order of priority.)

  • frame 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.

recordWFDB Record, optional

The Record object to be plotted.

annotationWFDB Annotation, optional

The Annotation object to be plotted.

plot_symbool, optional

Whether to plot the annotation symbols on the graph.

time_unitsstr, optional

The x axis unit. Allowed options are: ‘samples’, ‘seconds’, ‘minutes’, and ‘hours’.

titlestr, optional

The title of the graph.

sig_stylelist, 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_stylelist, 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_gridslist, 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’.

figsizetuple, optional

Tuple pair specifying the width, and height of the figure. It is the ‘figsize’ argument passed into matplotlib.pyplot’s figure function.

return_figbool, optional

Whether the figure is to be returned as an output argument.

sharexbool or ‘auto’, optional

Whether the X axis should be shared between all subplots. If set to True, then all signals will be aligned with each other. If set to False, then each subplot can be panned/zoomed independently. If set to ‘auto’ (default), then the X axis will be shared unless record is multi-frequency and the time units are set to ‘samples’.

figurematplotlib 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')