WFDB Plot无法使用文档中的代码

时间:2018-08-27 19:05:41

标签: python

我正在开始使用WFDB(我是该库的新手),它给我的错误消息是我直接从文档中获得的代码。

import wfdb
record = wfdb.rdsamp('mitdb/100', sampto=3000)
#annotation = wfdb.rdann('sampledata/100', 'atr', sampto=3000)
ann = wfdb.rdann('mitdb/100', 'atr', sampto=3000)
wfdb.plot_items(signal=record,
                #annotation=[ann.sample, ann.sample],
                title='MIT-BIH Record 100', time_units='seconds',
                figsize=(10,4), ecg_grids='all')

给出错误代码:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-9ebb6f5d549b> in <module>()
      2                     #annotation=[ann.sample, ann.sample],
      3                     title='MIT-BIH Record 100', time_units='seconds',
----> 4                     figsize=(10,4), ecg_grids='all')

~/anaconda3/lib/python3.6/site-packages/wfdb/plot/plot.py in plot_items(signal, ann_samp, ann_sym, fs, time_units, sig_name, sig_units, ylabel, title, sig_style, ann_style, ecg_grids, figsize, return_fig)
     99 
    100     # Figure out number of subplots required
--> 101     sig_len, n_sig, n_annot, n_subplots = get_plot_dims(signal, ann_samp)
    102 
    103     # Create figure

~/anaconda3/lib/python3.6/site-packages/wfdb/plot/plot.py in get_plot_dims(signal, ann_samp)
    126     "Figure out the number of plot channels"
    127     if signal is not None:
--> 128         if signal.ndim == 1:
    129             sig_len = len(signal)
    130             n_sig = 1

AttributeError: 'tuple' object has no attribute 'ndim'

文档中直接包含了plot_items代码,因此它应该起作用,因为我使用的数据直接来自其库。这是错误还是我错过了什么?我注释掉了注释代码,因为它返回:

TypeError: plot_items() got an unexpected keyword argument 'annotation'

这是令人困惑的,因为此代码直接来自文档。

我试图做一个更简单的命令,但它带有一个我不知道的错误代码。

wfdb.plot.plot_wfdb(record=record)

输出:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-c3814c09f768> in <module>()
----> 1 wfdb.plot.plot_wfdb(record=record)

~/anaconda3/lib/python3.6/site-packages/wfdb/plot/plot.py in plot_wfdb(record, annotation, plot_sym, time_units, title, sig_style, ann_style, ecg_grids, figsize, return_fig)
    405         ylabel, record_name) = get_wfdb_plot_items(record=record,
    406                                                    annotation=annotation,
--> 407                                                    plot_sym=plot_sym)
    408 
    409     return plot_items(signal=signal, ann_samp=ann_samp, ann_sym=ann_sym, fs=fs,

~/anaconda3/lib/python3.6/site-packages/wfdb/plot/plot.py in get_wfdb_plot_items(record, annotation, plot_sym)
    421     # Get record attributes
    422     if record:
--> 423         if record.p_signal is not None:
    424             signal = record.p_signal
    425         elif record.d_signal is not None:

AttributeError: 'tuple' object has no attribute 'p_signal'

1 个答案:

答案 0 :(得分:0)

https://github.com/MIT-LCP/wfdb-python解决了这些问题,我花了几个小时才能找到解决该问题的方法。