Matplotlib Coherence 图 ValueError
Matplotlib Coherence plot ValueError
我正在尝试使用以下代码从导入的 csv 中绘制类似于 Matplotlib Gallery 的一致性图:
r1 = mru['r1']
r2 = mru['r2']
t = mru['time']
plt.cohere(t, r1, 'b-', t, r2, 'g-', ax=ax10)
ax10.xlim(0,5)
ax10.xlabel('time')
ax10.ylabel('r1 and r2')
ax10.grid(True)
我收到这个错误:
ValueError: Coherence is calculated by averaging over *NFFT*
length segments. Your signal is too short for your choice of *NFFT*
所以我把值改成了二:
plt.cohere(t, r1, 'b-', t, r2, 'g-', NFFT=2, ax=ax10)
并得到这个错误:
TypeError: cohere() got multiple values for keyword argument 'NFFT'
如何正确绘制相关性?
您传递给 cohere()
的参数是错误的。你不需要时间,你只需要 r1
和 r2
这两个系列,以及共同的采样率 Fs
.
您收到原始错误消息是因为根据文档 (http://matplotlib.org/api/mlab_api.html#matplotlib.mlab.cohere),该函数希望 NFFT 成为第三个参数,并且它以某种方式将 'b-'
解释为数字。当您在别处明确定义 NFFT 时,您就在加倍定义 NFFT。
尝试
plt.cohere(r1, r2, NFFT=256)
或者您需要的任何 NFFT 值。确保你的采样率也正确,否则你的结果将没有物理意义。
我正在尝试使用以下代码从导入的 csv 中绘制类似于 Matplotlib Gallery 的一致性图:
r1 = mru['r1']
r2 = mru['r2']
t = mru['time']
plt.cohere(t, r1, 'b-', t, r2, 'g-', ax=ax10)
ax10.xlim(0,5)
ax10.xlabel('time')
ax10.ylabel('r1 and r2')
ax10.grid(True)
我收到这个错误:
ValueError: Coherence is calculated by averaging over *NFFT*
length segments. Your signal is too short for your choice of *NFFT*
所以我把值改成了二:
plt.cohere(t, r1, 'b-', t, r2, 'g-', NFFT=2, ax=ax10)
并得到这个错误:
TypeError: cohere() got multiple values for keyword argument 'NFFT'
如何正确绘制相关性?
您传递给 cohere()
的参数是错误的。你不需要时间,你只需要 r1
和 r2
这两个系列,以及共同的采样率 Fs
.
您收到原始错误消息是因为根据文档 (http://matplotlib.org/api/mlab_api.html#matplotlib.mlab.cohere),该函数希望 NFFT 成为第三个参数,并且它以某种方式将 'b-'
解释为数字。当您在别处明确定义 NFFT 时,您就在加倍定义 NFFT。
尝试
plt.cohere(r1, r2, NFFT=256)
或者您需要的任何 NFFT 值。确保你的采样率也正确,否则你的结果将没有物理意义。