Visualization¶
ECG waveforms¶
plot_ecg_comparison
¶
plot_ecg_comparison(real: ECGDataset, synthetics: List[ECGDataset], sample_index: int = 0, leads: Optional[List[str]] = None, mode: str = 'overlay', add_calibration_pulse: bool = True) -> Figure
Plot one ECG recording from real and the corresponding sample from each synthetic dataset on ECG graph paper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
real
|
ECGDataset
|
|
required |
synthetics
|
list of ECGDataset
|
|
required |
sample_index
|
int
|
Which recording to visualise (0-indexed). |
0
|
leads
|
list of str
|
Subset of lead names to show. Defaults to all leads. |
None
|
mode
|
'overlay' | 'sidebyside' | 'grid'
|
|
'overlay'
|
add_calibration_pulse
|
bool
|
Prepend a 1 mV × 0.2 s calibration square wave to every trace. |
True
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in ecgen_eval/visualization/ecg_waveform.py
ECG graph paper¶
ECG graph paper background builder.
Creates a Plotly Figure pre-configured with the traditional ECG paper look: - Pink/salmon background - Light-red minor grid (1 mm = 0.04 s × 0.1 mV at 25 mm/s, 10 mm/mV) - Dark-red major grid (5 mm = 0.20 s × 0.5 mV)
All other visualization modules call make_ecg_paper_figure() as a factory
and add traces on top of the returned figure.
Reference for standard ECG paper dimensions: Kligfield, P., et al. (2007). Recommendations for the Standardization and Interpretation of the Electrocardiogram. Journal of the American College of Cardiology, 49(10), 1109–1127. https://doi.org/10.1016/j.jacc.2007.01.024
make_ecg_paper_figure
¶
make_ecg_paper_figure(n_rows: int, n_cols: int, row_labels: Optional[List[str]] = None, col_labels: Optional[List[str]] = None, x_range: Optional[Tuple[float, float]] = None, y_range: Optional[Tuple[float, float]] = None, fs: float = 500.0, subplot_height_px: int = 180, subplot_width_px: int = 380, shared_xaxes: bool = True, shared_yaxes: bool = False, title: str = '') -> Figure
Build a Plotly Figure with ECG graph-paper styling for a grid of subplots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_rows
|
int
|
Subplot grid dimensions. |
required |
n_cols
|
int
|
Subplot grid dimensions. |
required |
row_labels
|
list of str
|
Axis-level labels added as annotations. |
None
|
col_labels
|
list of str
|
Axis-level labels added as annotations. |
None
|
x_range
|
(float, float)
|
X-axis range in seconds. Default derived from minor/major grid defaults. |
None
|
y_range
|
(float, float)
|
Y-axis range in mV. Default: (-1.5, 1.5). |
None
|
fs
|
float
|
Sampling frequency (used only for tick label formatting hints). |
500.0
|
subplot_height_px
|
int
|
Pixel size per subplot panel. |
180
|
subplot_width_px
|
int
|
Pixel size per subplot panel. |
180
|
shared_xaxes
|
bool
|
Passed to make_subplots. |
True
|
shared_yaxes
|
bool
|
Passed to make_subplots. |
True
|
title
|
str
|
Figure title. |
''
|
Returns:
| Type | Description |
|---|---|
Figure
|
Pre-styled figure; caller adds traces via fig.add_trace(..., row=r, col=c). |
Source code in ecgen_eval/visualization/ecg_paper.py
get_synth_color
¶
Metric plots¶
Plotly-based plots for metric results.
Provides: - Per-lead bar chart - Distribution violin (for DTW pairwise distances) - Radar chart summarising all metrics across datasets
plot_per_lead_bar
¶
plot_per_lead_bar(results: Dict[str, MetricResult], metric_name: str, lead_names: Optional[List[str]] = None) -> Figure
Grouped bar chart: X = leads, bars = synthetic datasets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict mapping dataset_label → MetricResult
|
|
required |
metric_name
|
str (e.g. "MMD", "DTW")
|
|
required |
lead_names
|
list of str, optional — filter/order leads
|
|
None
|
Source code in ecgen_eval/visualization/metric_plots.py
plot_metric_violin
¶
plot_metric_violin(results: Dict[str, MetricResult], metric_name: str, dist_key: str = 'per_lead_all_distances', leads: Optional[List[str]] = None) -> Figure
Violin plot showing the distribution of pairwise distances per lead. Only meaningful for metrics that store per-pair distance lists in extra[dist_key].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict mapping dataset_label → MetricResult
|
|
required |
metric_name
|
str
|
|
required |
dist_key
|
str — key in MetricResult.extra that holds {lead: [distances]}
|
|
'per_lead_all_distances'
|
leads
|
list of str
|
|
None
|
Source code in ecgen_eval/visualization/metric_plots.py
plot_radar_chart
¶
plot_radar_chart(scores_by_dataset: Dict[str, Dict[str, float]], metric_names: Optional[List[str]] = None, higher_is_better: Optional[Dict[str, bool]] = None) -> Figure
Radar (spider) chart with one polygon per synthetic dataset. Scores are normalised so that the outer edge = best.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores_by_dataset
|
dataset_label: {metric_name: score}
|
|
dataset_label: {metric_name: score}
|
metric_names
|
order of metrics on radar axes
|
|
None
|
higher_is_better
|
metric_name: bool
|
|
metric_name: bool
|
Source code in ecgen_eval/visualization/metric_plots.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
plot_psd_overlay
¶
plot_psd_overlay(results: Dict[str, MetricResult], fs: float = 500.0, leads: Optional[List[str]] = None, max_freq_hz: float = 40.0) -> Figure
Overlay the mean normalised PSD of real vs. synthetic datasets per lead.
Only meaningful for PSDMetric results which store mean PSDs in
result.extra["per_lead_psd_real"] and result.extra["per_lead_psd_synth"].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict dataset_label → MetricResult
|
|
required |
fs
|
float sampling frequency (used to build frequency axis)
|
|
500.0
|
leads
|
list of str
|
|
None
|
max_freq_hz
|
float clip display to this frequency (default 40 Hz)
|
|
40.0
|
Source code in ecgen_eval/visualization/metric_plots.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
Clinical feature plots¶
2D and 3D distribution comparison plots for clinical ECG features.
All functions return self-contained Plotly Figure objects suitable for embedding in the HTML report.
plot_feature_2d
¶
plot_feature_2d(real_df: DataFrame, synth_df: DataFrame, x_feature: str, y_feature: str, synth_label: str = 'Synthetic', real_label: str = 'Real', max_scatter_pts: int = 500) -> Figure
2D distribution comparison for one feature pair.
Shows KDE contours (Histogram2dContour) plus a subsampled scatter overlay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
real_df
|
pd.DataFrame — summary feature DataFrames.
|
|
required |
synth_df
|
pd.DataFrame — summary feature DataFrames.
|
|
required |
x_feature
|
str — column names.
|
|
required |
y_feature
|
str — column names.
|
|
required |
synth_label
|
str — legend labels.
|
|
'Synthetic'
|
real_label
|
str — legend labels.
|
|
'Synthetic'
|
max_scatter_pts
|
int — cap on scatter points to keep plot fast.
|
|
500
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in ecgen_eval/visualization/feature_plots.py
plot_feature_pair_grid
¶
plot_feature_pair_grid(real_df: DataFrame, synth_df: DataFrame, pairs: Optional[List[Tuple[str, str]]] = None, synth_label: str = 'Synthetic', real_label: str = 'Real') -> Figure
Grid of 2D distribution comparison subplots, one per feature pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pairs
|
list of (x_feature, y_feature) tuples.
|
|
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in ecgen_eval/visualization/feature_plots.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
plot_feature_2d_multi
¶
plot_feature_2d_multi(real_df: DataFrame, synth_dfs: List[DataFrame], x_feature: str, y_feature: str, synth_labels: Optional[List[str]] = None, real_label: str = 'Real', max_scatter_pts: int = 400) -> Figure
2D scatter for real + multiple synthetic DataFrames.
Source code in ecgen_eval/visualization/feature_plots.py
plot_feature_3d
¶
plot_feature_3d(real_df: DataFrame, synth_df: DataFrame, x_feature: str, y_feature: str, z_feature: str, synth_label: str = 'Synthetic', real_label: str = 'Real', max_scatter_pts: int = 600) -> Figure
Interactive 3D scatter comparing real and synthetic feature distributions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
real_df
|
DataFrame
|
|
required |
synth_df
|
DataFrame
|
|
required |
x_feature
|
str — column names.
|
|
required |
y_feature
|
str — column names.
|
|
required |
z_feature
|
str — column names.
|
|
required |
Returns:
| Type | Description |
|---|---|
Figure(Scatter3d)
|
|
Source code in ecgen_eval/visualization/feature_plots.py
plot_feature_triple_grid
¶
plot_feature_triple_grid(real_df: DataFrame, synth_df: DataFrame, triples: Optional[List[Tuple[str, str, str]]] = None, synth_label: str = 'Synthetic', real_label: str = 'Real') -> Figure
Grid of 3D scatter subplots, one per feature triple.
Because Plotly does not support 3D scene subplots via make_subplots as intuitively as 2D, we stack scenes (scene, scene2, scene3, …) manually.
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in ecgen_eval/visualization/feature_plots.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |