Plotting .mat ECG to 50mm ECG visualisation
12:36 06 Mar 2023

I'm trying to graph .mat files from this database https://data.mendeley.com/datasets/7dybx7wyfn/3 and saving them as an .svg or .png using ecg-plot 0.2.8 (https://pypi.org/project/ecg-plot/).

I'm been at it for a couple of days without any luck, underneath is my method:

  1. Download the database
  2. Writing a py script inside the folder containing .mat files to try to save a single ecg graph (see picture and code): enter image description here

Script:

import ecg_plot
ecg = '228m (10).mat'
ecg_plot.plot_12(ecg, sample_rate = 500, title = 'ECG 12')
ecg_plot.save_as_png('example_ecg', 'tmp/')

This gives the resulting error:

    (base) agfr@Ages-MacBook-Pro 1 NSR % python3 main.py 
Traceback (most recent call last):
  File "/Users/agfr/Documents/MLII/1 NSR/main.py", line 4, in 
    ecg_plot.plot_12(ecg, sample_rate = 500, title = 'ECG 12')
  File "/Users/agfr/opt/anaconda3/lib/python3.9/site-packages/ecg_plot/ecg_plot.py", line 83, in plot_12
    _ax_plot(t_ax, np.arange(0, len(ecg[t_lead])*step, step), ecg[t_lead], seconds)
  File "/Users/agfr/opt/anaconda3/lib/python3.9/site-packages/ecg_plot/ecg_plot.py", line 27, in _ax_plot
    ax.plot(x,y, linewidth=lwidth)
  File "/Users/agfr/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 1632, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "/Users/agfr/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 312, in __call__
    yield from self._plot_args(this, kwargs)
  File "/Users/agfr/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 449, in _plot_args
    linestyle, marker, color = _process_plot_format(fmt)
  File "/Users/agfr/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 199, in _process_plot_format
    raise ValueError(
ValueError: Unrecognized character 0 in format string

If anyone could help me understand what I'm doing wrong in the plotting the graph I would be very grateful! I've been trying to find an answer on stack overflow and google without any solutions.

python graph model.matrix