1

I am using obspy to look at some hydroacoustic data, and I need to view the data as a spectrogram. The spectrogram seems to be OK, but I would like to cut off the top (near the nyquist) of my plot around the y=100 mark. I am having a lot of trouble figuring out how to limit the y-axis on this. Is anyone able to provide some insight?

My code is below and the second from the bottom line: fig.axes[0].set_ylim(0,100) I feel should work, but I get an error saying 'list' object has no attribute 'axes'.

import obspy
from obspy.clients.fdsn import Client
from obspy.imaging.spectrogram import spectrogram
client = Client("IRIS")
from obspy import UTCDateTime
import numpy as np
import matplotlib.pyplot as plt



# Retrieve waveform data
t1 = UTCDateTime("2020-02-13T09:02:00.000")
t2 = UTCDateTime("2020-02-13T09:28:00.000")

# get_waveforms expects (network, station, location, channel, start_time, end_time)
# One station/channel
st = client.get_waveforms("IM","H11S1","","EDH",t1,t2)

""" Plot the timeseries waveform """
st.plot()


""" Plot the spectrogram """
fig = st.spectrogram(log=False, dbscale=True, axes=None, title='Spectrogram', cmap='inferno', show=False)
fig.axes[0].set_ylim(0,100)
plt.show()
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57

1 Answers1

0

I don't know a way to set a new y-axes limit of the figure. However, to cut-off the frequency range of the data, you can first downsample the data, and then do the spectrogram. There is the obspy resample fct (https://docs.obspy.org/packages/autogen/obspy.core.stream.Stream.resample.html) which does that job.

da0bi
  • 1
  • 1
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30895099) – Flair Jan 27 '22 at 18:20