Spectrogram and Matplotlib

Good afternoon, I have a question about plotting a spectrogram in a subplot of matplotlib.
I am new in Python and ObsPy and I’m trying to plot a sismogram in one subplot, and it’s respective spectrogram in the other subplot.
This is my current code

‘’’
fig2, ax2 = plt.subplots(ncols=1, nrows=2, figsize=(10, 4))
stT= read(“Cinchona_2009-01-07T16_41_47.999998Z_G.HDC.00.HHZ.sac”)
trT= stT[0]
ax2[0].plot(tr.data, ‘k-’)
Spectro = st.spectrogram(log=True, title= ‘Template Spectrogram’+ str(st[0].stats.starttime))
ax2[1].plot(Spectro)
plt.show()
‘’’
Can someone help me please?

Thanks in advance

Try axes=... that we provide for many plot routines: obspy.imaging.spectrogram.spectrogram — ObsPy 1.3.0.post0+7.g258f0d9c5d.obspy.master documentation

tr.spectrogram(..., axes=ax2[1])

Thank you so much, it really worked

1 Like