gpt4 book ai didi

python matplotlib : spectrogram plot using pre-computed spectral data array

转载 作者:太空宇宙 更新时间:2023-11-03 17:10:25 27 4
gpt4 key购买 nike

我有两个长度相等的时间序列(地震道的不同分量),我计算了它们的单独频谱图 PxV 和 PxH,它们对应于地震信号的垂直和水平分量。然后,我提取了每个频谱图的数据数组(对应于时间 - 频率空间中的点的幅度值)并对这些值应用了一些数学运算,在本例中将一个数组除以另一个数组,得到一个新的数组 PxHV。

如何将新数据数组 PxHV 传递给 matplotlib,以便以与 plt.specgram() 函数相同的方式绘制新数据数组?

P.S.,我相信我可以使用 PxZ 或 PxH 频谱图中的时间和频率数组(x 和 y 变量),因为它们对于所有绘图都是相同的。

这是我的代码的简化示例:

plt.subplot(411) PxV, freqsV, binsV, imV = plt.specgram(trV.data, NFFT
= 6000, noverlap = 2000, Fs = trV.stats.sampling_rate, detrend = 'mean', mode = 'psd')
plt.title('Vertical')
plt.xlabel('Time [s]')
plt.ylabel('Frequency [Hz]')
plt.clim(-50, 50)
plt.colorbar()

plt.subplot(412) PxE, freqsE, binsE, imE = plt.specgram(trE.data, NFFT
= 6000, noverlap = 2000, Fs = trE.stats.sampling_rate, detrend = 'mean', mode = 'psd')
plt.title('East')
plt.xlabel('Time [s]')
plt.ylabel('Frequency [Hz]')
plt.clim(-50, 50)
plt.colorbar()

plt.subplot(413) PxN, freqsN, binsN, imN = plt.specgram(trN.data, NFFT
= 6000, noverlap = 2000, Fs = trN.stats.sampling_rate, detrend = 'mean', mode = 'psd')
plt.title('North')
plt.xlabel('Time [s]')
plt.ylabel('Frequency [Hz]')
plt.clim(-50, 50)
plt.colorbar()

PxH = np.sqrt(np.multiply(PxE, PxN))
PxHV = np.divide(PxH, PxV)

plt.subplot(414)

**Need code here to pass PxHV "spectrogram array" to matplotlib**

plt.title('H/V')
plt.xlabel('Time [s]')
plt.ylabel('Frequency [Hz]')
plt.colorbar()


plt.show()

最佳答案

我已经弄清楚了 - 使用 matplotlib.pyplot.pcolourmesh 方法。

关于python matplotlib : spectrogram plot using pre-computed spectral data array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34151403/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com