biopsykit.signals.ecg.plotting module

Module providing functions for plotting ECG data.

biopsykit.signals.ecg.plotting.ecg_plot(ecg_processor=None, key=None, ecg_signal=None, heart_rate=None, sampling_rate=256, plot_ecg_signal=True, plot_distribution=True, plot_individual_beats=True, **kwargs)[source]

Plot ECG processing results.

By default, this plot consists of four subplots:

  • top left: course of ECG signal plot with signal quality indicator, detected R peaks and R peaks marked as outlier

  • bottom left: course of heart rate (tachogram)

  • top right: individual heart beats overlaid on top of each other

  • bottom right: heart rate distribution (histogram)

To use this function, either simply pass an EcgProcessor object together with a key indicating which phase needs to be processed should be processed or the two dataframes ecg_signal and heart_rate resulting from ecg_process().

Parameters
  • ecg_processor (EcgProcessor, optional) – EcgProcessor object. If this argument is supplied, the key argument needs to be supplied as well.

  • key (str, optional) – Dictionary key of the phase to process. Needed when ecg_processor is passed as argument.

  • ecg_signal (EcgResultDataFrame, optional) – Dataframe with processed ECG signal. Output from ecg_process().

  • heart_rate (DataFrame, optional) – Dataframe with heart rate output. Output from ecg_process().

  • sampling_rate (float, optional) – Sampling rate of recorded data in Hz. Not needed if ecg_processor is supplied as parameter. Default: 256

  • plot_ecg_signal (bool, optional) – Whether to plot the cleaned ECG signal in a subplot or not. Default: True

  • plot_distribution (bool, optional) – Whether to plot the heart rate distribution in a subplot or not. Default: True

  • plot_individual_beats (bool, optional) – Whether to plot the individual heart beats in a subplot or not. Default: True

  • **kwargs

    Additional parameters to configure the plot. Parameters include:

    • figsize: Figure size

    • title: Optional name to add to plot title (after “Electrocardiogram (ECG)”)

    • legend_loc: Location of legend in plot. Passed as loc parameter to matplotlib.axes.Axes.legend().

    • legend_fontsize: Fontsize of legend text. Passed as fontsize parameter to matplotlib.axes.Axes.legend().

Returns

  • fig (Figure) – Figure object

  • axs (list of Axes) – list of subplot axes objects

Return type

Tuple[matplotlib.figure.Figure, Sequence[matplotlib.axes._axes.Axes]]

See also

hr_plot()

plot heart rate only

hr_distribution_plot()

plot heart rate distribution only

individual_beats_plot()

plot individual beats only

hrv_plot()

plot heart rate variability

biopsykit.signals.ecg.plotting.hr_plot(heart_rate, plot_mean=True, plot_outlier=False, outlier=None, **kwargs)[source]

Plot course of heart rate over time (tachogram).

This plot is also used as subplot in ecg_plot().

Parameters
  • heart_rate (DataFrame) – Dataframe with heart rate output. Output from ecg_process().

  • plot_mean (bool, optional) – Whether to plot the mean heart rate as horizontal line or not. Default: True

  • plot_outlier (bool, optional) – Whether to plot ECG signal outlier as vertical outlier or not. Default: False

  • outlier (ndarray, optional) – List of outlier indices. Only needed if plot_outlier is True. Default: None

  • **kwargs

    Additional parameters to configure the plot. Parameters include:

    • figsize: Figure size

    • title: Optional name to add to plot title (after “Electrocardiogram (ECG)”)

    • legend_loc: Location of legend in plot. Passed as loc parameter to matplotlib.axes.Axes.legend().

    • legend_fontsize: Fontsize of legend text. Passed as fontsize parameter to matplotlib.axes.Axes.legend().

    • ax: Pre-existing axes for the plot. Otherwise, a new figure and axes object are created and returned.

Returns

  • fig (Figure) – figure object

  • ax (Axes) – axes object

Return type

Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes]

See also

ecg_plot()

plot ECG overview

biopsykit.signals.ecg.plotting.hrv_plot(ecg_processor=None, key=None, ecg_signal=None, rpeaks=None, sampling_rate=256, plot_psd=True, **kwargs)[source]

Plot Heart Rate Variability results.

By default, it consists of 3 plots:

  • top left: RR interval distribution (histogram) including boxplot to visualize distribution and median

  • bottom left: Power Spectral Density (PSD) plot of RR intervals

  • right: Poincaré plot of RR intervals

To use this function, either simply pass an EcgProcessor object together with a key indicating which phase needs to be processed should be processed or the two dataframes ecg_signal and heart_rate resulting from ecg_process().

Parameters
  • ecg_processor (EcgProcessor, optional) – EcgProcessor object. If this argument is passed, the key argument needs to be supplied as well.

  • key (str, optional) – Dictionary key of the phase to process. Needed when ecg_processor is passed as argument.

  • ecg_signal (DataFrame, optional) – dataframe with processed ECG signal. Output from ecg_process().

  • rpeaks (RPeakDataFrame, optional) – Dataframe with detected R peaks. Output from ecg_process().

  • sampling_rate (float, optional) – Sampling rate of recorded data in Hz. Not needed if ecg_processor is supplied as parameter. Default: 256

  • plot_psd (bool, optional) – Whether to plot power spectral density (PDF) from frequency-based HRV analysis in a subplot or not. Default: True

  • **kwargs

    Additional parameters to configure the plot. Parameters include:

    • figsize: Figure size

    • title: Optional name to add to plot title (after “Electrocardiogram (ECG)”)

    • legend_loc: Location of legend in plot. Passed as loc parameter to matplotlib.axes.Axes.legend().

    • legend_fontsize: Fontsize of legend text. Passed as fontsize parameter to matplotlib.axes.Axes.legend().

    • ax: Pre-existing axes for the plot. Otherwise, a new figure and axes object are created and returned.

Returns

  • fig (Figure) – figure object

  • ax (Axes) – axes object

Return type

Tuple[matplotlib.figure.Figure, Sequence[matplotlib.axes._axes.Axes]]

See also

rr_distribution_plot()

plot RR interval distribution

hrv_poincare_plot()

plot HRV using Poincaré plot

hrv_frequency_plot()

plot Power Spectral Density (PSD) of RR intervals

biopsykit.signals.ecg.plotting.hr_distribution_plot(heart_rate, **kwargs)[source]

Plot heart rate distribution (histogram).

This plot is also used as subplot in ecg_plot().

Parameters
  • heart_rate (DataFrame, optional) – dataframe with heart rate output. Output from ecg_process()

  • **kwargs

    Additional parameters to configure the plot. Parameters include:

    • figsize: Figure size

    • ax: Pre-existing axes for the plot. Otherwise, a new figure and axes object are created and returned.

Returns

  • fig (Figure) – figure object

  • ax (Axes) – axes object

Return type

Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes]

See also

ecg_plot()

plot ECG overview

biopsykit.signals.ecg.plotting.rr_distribution_plot(rpeaks, sampling_rate=256, **kwargs)[source]

Plot distribution of RR intervals (histogram) with boxplot and rugplot.

This plot is also used as subplot in hrv_plot().

Parameters
  • rpeaks (DataFrame, optional) – dataframe with R peaks. Output of ecg_process().

  • sampling_rate (float, optional) – Sampling rate of recorded data in Hz. Default: 256

  • **kwargs

    Additional parameters to configure the plot. Parameters include:

    • figsize: Figure size

    • ax: Pre-existing axes for the plot. Otherwise, a new figure and axes object are created and returned.

Returns

  • fig (Figure) – figure object

  • ax (Axes) – axes object

Return type

Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes]

See also

hr_distribution_plot()

plot heart rate distribution (without boxplot and rugplot)

biopsykit.signals.ecg.plotting.hrv_frequency_plot(rpeaks, sampling_rate=256, **kwargs)[source]

Plot Power Spectral Density (PSD) of RR intervals.

This plot is also used as subplot in hrv_plot().

Parameters
  • rpeaks (RPeakDataFrame) – Dataframe with detected R peaks. Output from ecg_process().

  • sampling_rate (float, optional) – Sampling rate of recorded data in Hz. Default: 256

  • **kwargs

    Additional parameters to configure the plot. Parameters include:

    • figsize: Figure size

    • ax: Pre-existing axes for the plot. Otherwise, a new figure and axes object are created and returned.

Returns

  • fig (Figure) – figure object

  • ax (Axes) – axes object

Return type

Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes]

See also

hrv_plot()

plot heart rate variability

biopsykit.signals.ecg.plotting.hrv_poincare_plot(rpeaks, sampling_rate=256, **kwargs)[source]

Plot Heart Rate Variability as Poincaré Plot.

This plot is also used as subplot in hrv_plot().

Parameters
  • rpeaks (RPeakDataFrame) – Dataframe with detected R peaks. Output from ecg_process().

  • sampling_rate (float, optional) – Sampling rate of recorded data in Hz. Default: 256

  • **kwargs

    Additional parameters to configure the plot. Parameters include:

    • figsize: Figure size

    • ax: List of pre-existing axes for the plot. Otherwise, a new figure and list of axes objects are created and returned.

Returns

  • fig (Figure) – Figure object

  • axs (list of Axes) – list of subplot axes objects

Return type

Tuple[matplotlib.figure.Figure, Sequence[matplotlib.axes._axes.Axes]]

See also

hrv_plot()

plot heart rate variability

biopsykit.signals.ecg.plotting.individual_beats_plot(ecg_signal, rpeaks=None, sampling_rate=256, **kwargs)[source]

Plot all segmented heart beats overlaid on top of each other.

This plot is also used as subplot in ecg_plot().

Parameters
  • ecg_signal (EcgResultDataFrame, optional) – Dataframe with processed ECG signal. Output from ecg_process().

  • rpeaks (RPeakDataFrame, optional) – Dataframe with detected R peaks or None to infer R peaks from ecg_signal. Default: None

  • sampling_rate (float, optional) – Sampling rate of recorded data in Hz. Default: 256

  • **kwargs

    Additional parameters to configure the plot. Parameters include:

    • figsize: Figure size

    • ax: Pre-existing axes for the plot. Otherwise, a new figure and axes object are created and returned.

Returns

  • fig (Figure) – figure object

  • ax (Axes) – axes object

Return type

Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes]

See also

ecg_plot()

plot ECG overview