Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: unable to plot single channel record #308

Merged
merged 1 commit into from
Jun 21, 2021

Conversation

biggates
Copy link
Contributor

Problem:

Unable to plot a record with only one channel

Cause:

In plot.py: plot_signal(), plot_annotation() and plot_ecg_grids() uses axes as lists, e.g. :

# in plot.py: plot_signal():

    # Plot the signals
    if signal.ndim == 1:
        axes[0].plot(t, signal, sig_style[0], zorder=3)

Steps to reproduce:

>>> import wfdb
>>> record = wfdb.rdrecord('sample-data/100', sampto=3000)
>>> wfdb.plot_wfdb(record)
# This figure is well-plotted

# now try the same record, with only one channel:
>>> record2 = wfdb.rdrecord('sample-data/100', sampto=3000, channel_names=['V5']) 
>>> wfdb.plot_wfdb(record2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\git\wfdb-python\wfdb\plot\plot.py", line 642, in plot_wfdb
    return plot_items(signal=signal, ann_samp=ann_samp, ann_sym=ann_sym, fs=fs,
  File "C:\git\wfdb-python\wfdb\plot\plot.py", line 119, in plot_items
    plot_signal(signal, sig_len, n_sig, fs, time_units, sig_style, axes)       
  File "C:\git\wfdb-python\wfdb\plot\plot.py", line 283, in plot_signal        
    axes[ch].plot(t, signal[:,ch], sig_style[ch], zorder=3)
TypeError: 'AxesSubplot' object is not subscriptable

Fix:

Return a list manually if n_subplots == 1

@briangow
Copy link
Contributor

@biggates, thanks for figuring this out before we got to it! It looks good to me.

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