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

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

matplotlib.pyplot.cohere()功能:

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

39a22faacb2870554103624ed4944c00.png

用法: 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()

输出:

8d51dc38128e47d6d7ec983676fb6a8c.png

示例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()

输出:

65f759f27fac1dad381449b29283952c.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值