Nukolas
Nukolas

Reputation: 495

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

I have two timeseries' of equal length (different components of a seismic trace) for which I have computed individual spectrograms, PxV and PxH which correspond to the vertical and horizintal component of the seismic signal. I have then extracted the data array for each spectrogram (the amplitude values corresponsing to points in time - frequency space) and applied some math to the values, in this case dividing one array by the other, resulting in a new array PxHV.

How do I pass my new data array, PxHV to matplotlib in order to plot the new data array in the same what as the plt.specgram() function?

P.S., I believe that I can use the time and frequency arrays (x and y variables) from the either of the PxZ or PxH spectrograms, as they will be identical for all plots.

Here is a simplified example of my code:

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

Upvotes: 1

Views: 839

Answers (1)

Nukolas
Nukolas

Reputation: 495

I have figured it out - use the matplotlib.pyplot.pcolourmesh method.

Upvotes: 1

Related Questions