1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python matplotlib pyplot方法 Python matplotlib.pyplot.cohere()用法及代码示例

python matplotlib pyplot方法 Python matplotlib.pyplot.cohere()用法及代码示例

时间:2023-04-14 04:41:20

相关推荐

python matplotlib pyplot方法 Python matplotlib.pyplot.cohere()用法及代码示例

Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,该模块提供了MATLAB-like接口。在Pyplot中可以使用各种图,例如线图,轮廓图,直方图,散点图,3D图等。

matplotlib.pyplot.cohere()功能:

matplotlib库的pyplot模块中的cohere()函数用于绘制x和y之间的相干性。相干性是归一化的交叉频谱密度。

用法: matplotlib.pyplot.cohere(x, y, NFFT=256, Fs=2, Fc=0, detrend=, window=, noverlap=0, pad_to=None, sides=’default’, scale_by_freq=None, *, data=None, **kwargs)

参数:此方法接受以下描述的参数:

x, y:这些参数是数据序列。

Fs:此参数是标量。默认值为2。

window:此参数将数据段作为参数,并返回该段的窗口版本。其默认值为window_hanning()

sides:此参数指定要返回频谱的哪一侧。它可以具有以下值:‘default’,‘onesided’和‘twosided’。

pad_to:此参数包含填充数据段的整数值。

Fc:此参数还包含一个整数值,用于抵消曲线图的x范围以反映频率范围。其默认值为0

NFFT:此参数包含每个块中用于FFT的数据点数。

detrend:此参数包含应用于fft-ing之前的每个段的函数,旨在删除均值或线性趋势{‘none’,‘mean’,‘linear’}。

scale_by_freq:该参数允许对返回的频率值进行积分。

noverlap:此参数是块之间的重叠点数。

Fc:此参数是x的中心频率。

返回值:这将返回以下内容:

Cxy:这将返回相干矢量。

freqs:这将返回Cxy中元素的频率。

结果是(Cxy,freqs)

以下示例说明了matplotlib.axes中的matplotlib.pyplot.figure()函数:

范例1:

# Implementation of matplotlib function

import numpy as np

import matplotlib.pyplot as plt

dt = 0.01

t = np.arange(0, 30, dt)

nse1 = np.random.randn(len(t))

nse2 = np.random.randn(len(t))

s1 = 1.5 * np.sin(2 * np.pi * 10 * t) + nse1

s2 = np.cos(np.pi * t) + nse2

plt.cohere(s1, s2**2, 128, 1./dt)

plt.xlabel('time')

plt.ylabel('coherence')

plt.title('matplotlib.pyplot.cohere() Example\n',

fontsize = 14, fontweight ='bold')

plt.show()

输出:

示例2:

# Implementation of matplotlib function

import numpy as np

import matplotlib.pyplot as plt

dt = 0.01

t = np.arange(0, 30, dt)

nse1 = np.random.randn(len(t))

nse2 = np.random.randn(len(t))

r = np.exp(-t / 0.05)

cnse1 = np.convolve(nse1, r, mode ='same')*dt

cnse2 = np.convolve(nse2, r, mode ='same')*dt

s1 = 1.5 * np.sin(2 * np.pi * 10 * t) + cnse1

s2 = np.cos(np.pi * t) + cnse2 + np.sin(2 * np.pi * 10 * t)

fig, [ax1, ax2] = plt.subplots(2, 1)

ax1.set_title('matplotlib.pyplot.cohere() Example\n',

fontsize = 14, fontweight ='bold')

ax1.plot(t, s1, t, s2)

ax1.set_xlim(0, 5)

ax1.set_xlabel('time')

ax1.set_ylabel('s1 and s2')

ax1.grid(True)

ax2.cohere(s1, s2, 256, 1./dt)

ax2.set_ylabel('coherence')

plt.show()

输出:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。