waveform plot

Dear all,

I am trying to plot simple figure of waveforms (not so simple that I could just use plot() )

Here is the code I have:

tstart = UTCDateTime(detection.detect_time - 5.0)
tend = UTCDateTime(detection.detect_time + 20.0)

st1 = sta.copy()
st1a = st1.slice(starttime=tstart, endtime=tend)
st1det = st1a.detrend(type=‘constant’)

st1deta = st1det.copy()
st1filta = st1deta.filter(‘bandpass’, freqmin=fminb, freqmax=fmaxb, zerophase=True)

#time vector
t = np.arange(0, st1a[0].stats.npts / st1a[0].stats.sampling_rate, st1a[0].stats.delta)

#setup figure
fig = plt.figure(figsize=(20,40))
ax1a = fig.add_axes([0.07, 0.92, 0.9, 0.075])

#plot wfs
ax1a.plot(t, st1filta[0], ‘k’)
#ax1a.axvline(detection.detect_time, color=‘k’, linestyle=’–’)

Hello Blaz,

I think you just have to subtract tstart from detection.detect_time to get the relative time which is 5.0 in your case.

ax1a.axvline(detection.detect_time - tstart, color=‘k’, linestyle=’–‚)


ax1a.axvline(5.0, color=‘k’, linestyle=’—’)

I hope that helps.



You are doing a relative-type plot in seconds starting at 0 (the
starttime of the trace in your case), so you also need to convert your
absolute time you want to plot into that relative timeframe to match
your "time vector". In your failed attempt you had the waveform plot at
very low x values (-5 to 20, I think) and the vertical line at a high
value (something like 1e9 -- the float representation of the UTCDateTime
object, i.e. the POSIX timestamp).

You need to do something like..

ax1a.axvline(detection.detect_time - st1a[0].stats.starttime, ...)

..to get the relative timing of you detection time. Although, in your
example code the cut out time window is hard coded anyway, so your
vertical line should be at 5 seconds in the given example.

Please also note that you can use a convenience method to get the "time

ax1a.plot(st1filta[0].times(), st1filta[0], 'k')

Also see some related convenience changes in current master that will
enter 1.1 once it's released (not very soon), especially if at some
point you want absolute times on the x axis:


Thank you!

It works without problem.