Skip to content

Conversation

@johndgiese
Copy link
Contributor

When running the latest version of the code, the example didn't run without adding these two arguments.

When running the latest version of the code, the example didn't run without adding these two arguments.
@tompollard
Copy link
Member

The existing code fails with the following error:

import wfdb

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

Traceback (most recent call last):
  File "/Users/tompollard/projects/wfdb-python/wfdb/plot/plot.py", line 488, in _plot_signal
    t = tarrays[ch_len, ch_freq]
KeyError: (3000, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tompollard/projects/wfdb-python/wfdb/plot/plot.py", line 261, in plot_items
    _plot_signal(
  File "/Users/tompollard/projects/wfdb-python/wfdb/plot/plot.py", line 495, in _plot_signal
    "minutes": ch_freq * 60,
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

Updating the arguments as suggested fixes this issue:

import wfdb

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],
                fs=record.fs, sig_units=record.units,
                title='MIT-BIH Record 100', time_units='seconds',
                figsize=(10,4), ecg_grids='all')

Figure_1

Presumably the behaviour of plot_items changed at some point. It feels like this shouldn't be failing just because these arguments aren't provided (e.g. if units are unknown, just display "Unknown").

Copy link
Member

@tompollard tompollard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @johndgiese!

@tompollard tompollard merged commit 1eb04bd into MIT-LCP:main May 3, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants