Home>

I output the time series data and the spectrogram that analyzed the frequency using the wavelet transform, but the x-axis of the graph of the time series data and the x-axis of the color map are different.
How should I change the program to align the two x-axis?

Corresponding source code
m = 6
#Frequency band to analyze [Hz]
list1 = range (1, 80, 1)
print ("start")
for freq in list1:
    print (freq, end = "")
    print ('-', end = "")
    mw2 = signal.morlet (int (fs/freq * m * 2), m, 1.0, complete = True)
    corr_tmp = np.correlate (ags_data, mw2)/sum (abs (mw2))
    sup_first = np.zeros (int (len (mw2)/2))
    sup_end = np.zeros (len (ags_data)-len (corr_tmp)-int (len (mw2)/2))
    corr_tmp = np.append (sup_first, corr_tmp)
    corr_tmp = np.append (corr_tmp, sup_end)
    if freq == list1 [0]:
        corr_stack = abs (corr_tmp [: 10]) ** 2
    else: else:
        corr_stack = np.vstack ((corr_stack, abs (corr_tmp [:: 10]) ** 2))
print ("end")
#Image map output stage
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
xsl = ags_data [::10]
xmin = xsl.min ()
xmax = xsl.max ()
ymin = list1.start
ymax = list1.stop
fig = plt.figure (figsize = (8,4))
gs = gridspec.GridSpec (2,1)
ax1 = fig.add_subplot (gs [0,:])
plt.plot (df.index, ags_data, linewidth = 1)
plt.title ("sample_waveform")
plt.xlabel ("Time [s]")
plt.ylabel ("Amplitude")

plt.grid (True)
ax1.axis ('tight')
# plt.xlim ([0,5])
ax2 = fig.add_subplot (gs [1, :])
im = ax2.imshow (corr_stack, extent = [xmin, xmax, ymin, ymax], interpolation ='none', cmap ='jet', origin ='lower')
plt.title ("wavelet_coherence")
plt.xlabel ("Time [s]")
plt.ylabel ("Frequency [Hz]")
plt.grid (linestyle ='-', linewidth = 0.5)
plt.xticks ()

#I want to add a color bar ↓ Reference
# https://matplotlib.org/2.0.2/examples/pylab_examples/colorbar_tick_labelling_demo.html
cmlb = [0,0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1]
cbar = fig.colorbar (im, ticks = cmlb, orientation ='horizontal')
cbar.ax.set_xticklabels (cmlb) # horizontal colorbar

ax2.axis ('tight')


  • Answer # 1

    It was solved by setting extent = [df.index [0], de.index [-1], ymin, ymax].