Static Plots (matplotlib)¶
All static plot functions display the figure automatically by default (show=True). Pass show=False to suppress display and get back the matplotlib.figure.Figure for saving or further customization. Functions with an ax parameter can render into an existing axes for composability; when ax=None, a new figure is created.
Lead Waveforms¶
Plot a single ECG lead waveform |
|
Plot multiple leads in a grid layout |
|
Plot 12 leads with standard lead names (I, II, III, aVR, …, V6) |
- ecgdatakit.plotting.plot_lead(lead, peaks=None, title=None, show_grid=False, figsize=(12, 3), ax=None, *, fs=None, show=True, x_axis='time')[source]¶
Plot a single ECG lead waveform.
- Parameters:
lead (
Lead|ndarray[tuple[Any,...],dtype[double]]) – ECG lead or raw signal array to plot.peaks (
ndarray[tuple[Any,...],dtype[int_]] |None) – Optional R-peak indices to mark.title (
str|None) – Figure title. Defaults to the lead label.show_grid (
bool) – Draw ECG paper-style grid (defaultTrue).figsize (
tuple[float,float]) – Figure size in inches (default(12, 3)).ax (
Axes|None) – Existing axes to draw on. A new figure is created ifNone.fs (
int|None) – Sample rate in Hz. Required when lead is a numpy array.show (
bool) – Display the plot immediately (defaultTrue). Set toFalseto return the figure without displaying.x_axis (
str) –"time"for seconds (default) or"samples"for sample indices (1, 2, …, N).
- Return type:
Figure
- ecgdatakit.plotting.plot_leads(leads, peaks_dict=None, title=None, show_grid=False, figsize=(12, None), share_x=True, *, fs=None, show=True, x_axis='time', rows=None, cols=None)[source]¶
Plot multiple leads in a grid layout (vertical stack by default).
- Parameters:
leads (
list[Lead] |ECGRecord|ndarray[tuple[Any,...],dtype[double]] |list[ndarray[tuple[Any,...],dtype[double]]]) – Leads to plot. Also accepts a 2-D numpy array (n_leads × n_samples) or a list of 1-D numpy arrays.peaks_dict (
dict[str,ndarray[tuple[Any,...],dtype[int_]]] |None) –{label: peaks_array}for per-lead R-peak markers.show_grid (
bool) – Draw ECG paper-style grid.figsize (
tuple[float,float|None]) – Width is fixed; height is auto-calculated (2 in per row) whenNone.share_x (
bool) – Share the x-axis across all subplots (defaultTrue).fs (
int|None) – Sample rate in Hz. Required when leads is a numpy array.show (
bool) – Display the plot immediately (defaultTrue).x_axis (
str) –"time"for seconds (default) or"samples"for sample indices.rows (
int|None) – Number of rows in the subplot grid. Derived from cols or defaults to one row per lead when neither is given.cols (
int|None) – Number of columns in the subplot grid (default1).
- Return type:
Figure
- ecgdatakit.plotting.plot_12lead(leads, record=None, title=None, show_grid=False, figsize=(12, None), share_x=True, *, fs=None, show=True, x_axis='time', rows=None, cols=None)[source]¶
Plot 12 leads with standard lead names (I, II, III, aVR, …, V6).
Unlike
plot_leads(), this function assigns the standard 12-lead names when the input contains unnamed leads (e.g. a raw numpy array). The full signal is plotted without cropping.- Parameters:
leads (
list[Lead] |ECGRecord|ndarray[tuple[Any,...],dtype[double]] |list[ndarray[tuple[Any,...],dtype[double]]]) – Leads (or full record) to plot. Also accepts a 2-D numpy array (n_leads × n_samples) or a list of 1-D numpy arrays.record (
ECGRecord|None) – If provided, a header with patient/device/measurement info is shown.show_grid (
bool) – Draw ECG paper-style grid (defaultTrue).figsize (
tuple[float,float|None]) – Width is fixed; height is auto-calculated (2 in per row) whenNone.share_x (
bool) – Share the x-axis across all subplots (defaultTrue).fs (
int|None) – Sample rate in Hz. Required when leads is a numpy array.show (
bool) – Display the plot immediately (defaultTrue).x_axis (
str) –"time"for seconds (default) or"samples"for sample indices.rows (
int|None) – Number of rows in the subplot grid. Derived from cols or defaults to one row per lead when neither is given.cols (
int|None) – Number of columns in the subplot grid (default1).
- Return type:
Figure
Annotations & Beats¶
Plot lead with R-peak markers and RR interval annotations |
|
Plot segmented heartbeats |
|
Plot ensemble-averaged beat with ±1 SD shading |
- ecgdatakit.plotting.plot_peaks(lead, peaks=None, title=None, figsize=(12, 3), ax=None, *, fs=None, show=True, x_axis='time')[source]¶
Plot lead with R-peak markers and RR interval annotations.
- Parameters:
lead (
Lead|ndarray[tuple[Any,...],dtype[double]]) – ECG lead or raw signal array to plot.peaks (
ndarray[tuple[Any,...],dtype[int_]] |None) – R-peak indices. Auto-detected ifNone.fs (
int|None) – Sample rate in Hz. Required when lead is a numpy array.show (
bool) – Display the plot immediately (defaultTrue).x_axis (
str) –"time"for seconds (default) or"samples"for sample indices.title (str | None)
ax (Axes | None)
- Return type:
Figure
- ecgdatakit.plotting.plot_beats(lead, beats=None, peaks=None, overlay=True, figsize=(8, 5), ax=None, *, fs=None, show=True)[source]¶
Plot segmented heartbeats.
- Parameters:
lead (
Lead|ndarray[tuple[Any,...],dtype[double]]) – Source ECG lead or raw signal array.beats (
list[Lead] |None) – Pre-segmented beats. Segmented automatically ifNone.peaks (
ndarray[tuple[Any,...],dtype[int_]] |None) – R-peak indices for segmentation.overlay (
bool) –True: overlay all beats;False: waterfall display.fs (
int|None) – Sample rate in Hz. Required when lead is a numpy array.show (
bool) – Display the plot immediately (defaultTrue).ax (Axes | None)
- Return type:
Figure
- ecgdatakit.plotting.plot_average_beat(lead, peaks=None, before=0.2, after=0.4, figsize=(6, 4), ax=None, *, fs=None, show=True)[source]¶
Plot ensemble-averaged beat with ±1 SD shading.
- Parameters:
lead (
Lead|ndarray[tuple[Any,...],dtype[double]]) – Source ECG lead or raw signal array.peaks (
ndarray[tuple[Any,...],dtype[int_]] |None) – R-peak indices.before (
float) – Seconds before R-peak.after (
float) – Seconds after R-peak.fs (
int|None) – Sample rate in Hz. Required when lead is a numpy array.show (
bool) – Display the plot immediately (defaultTrue).ax (Axes | None)
- Return type:
Figure
Frequency Domain¶
Plot power spectral density or FFT magnitude spectrum |
|
Plot time-frequency spectrogram (STFT) |
- ecgdatakit.plotting.plot_spectrum(lead, method='welch', figsize=(10, 4), ax=None, *, fs=None, show=True)[source]¶
Plot power spectral density or FFT magnitude spectrum.
- Parameters:
lead (
Lead|ndarray[tuple[Any,...],dtype[double]]) – ECG lead or raw signal array to analyse.method (
str) –"welch"for PSD or"fft"for magnitude spectrum.fs (
int|None) – Sample rate in Hz. Required when lead is a numpy array.show (
bool) – Display the plot immediately (defaultTrue).ax (Axes | None)
- Return type:
Figure
- ecgdatakit.plotting.plot_spectrogram(lead, nperseg=256, figsize=(12, 4), ax=None, *, fs=None, show=True)[source]¶
Plot time-frequency spectrogram (STFT).
- Parameters:
- Return type:
Figure
HRV¶
Plot RR interval tachogram |
|
Poincaré plot: RR(n) vs RR(n+1) with SD1/SD2 ellipse |
|
Combined HRV dashboard: tachogram, Poincaré, frequency bands, metrics |
- ecgdatakit.plotting.plot_rr_tachogram(rr_ms, figsize=(10, 3), ax=None, *, show=True)[source]¶
Plot RR interval tachogram.
- ecgdatakit.plotting.plot_poincare(rr_ms, figsize=(6, 6), ax=None, *, show=True)[source]¶
Poincaré plot: RR(n) vs RR(n+1) with SD1/SD2 ellipse.
Quality¶
Signal quality dashboard: SQI bar chart per lead |
- ecgdatakit.plotting.plot_quality(leads, figsize=(10, 5), *, fs=None, show=True)[source]¶
Signal quality dashboard: SQI bar chart per lead.
- Parameters:
leads (
list[Lead] |ECGRecord|ndarray[tuple[Any,...],dtype[double]] |list[ndarray[tuple[Any,...],dtype[double]]]) – Leads to assess. Also accepts a 2-D numpy array (n_leads × n_samples) or a list of 1-D numpy arrays.fs (
int|None) – Sample rate in Hz. Required when leads is a numpy array.show (
bool) – Display the plot immediately (defaultTrue).
- Return type:
Figure
Full Report¶
Comprehensive ECG report page |