Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
How to make spectrogram's x axis start from 0 and end at full duration?

I created a 4 seconds length of data and plotted its spectrogram. nperseg was specified as 100. Due to this window length, the x axis does not start from 0 and end at 4s. Is there a way to align spectrogram's time axis with the original time domain signal?

from scipy import signal
import matplotlib.pyplot as plt
import numpy as np

fs = 100
N = 400
time = np.arange(N) / float(fs)
y = 500*np.cos(2*np.pi*5*time)

f, t, Sxx = signal.spectrogram(y, fs, nperseg = 100)
plt.pcolormesh(t, f, Sxx, shading='gouraud')
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()

plt.plot(time, y)

One example is shown in the figure below, both time domain signal and spectrogram start from 0 and end at 1s. Time domain signal and spectrogram

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can plot as you did and use xlim to align the X axes.

from scipy import signal
import matplotlib.pyplot as plt
import numpy as np

fs = 100
N = 400
time = np.arange(N) / float(fs)
y = 500*np.cos(2*np.pi*5*time**2/2)

f, t, Sxx = signal.spectrogram(y, fs, nperseg = 100)

plt.subplot(211)
plt.pcolormesh(t, f, Sxx, shading='gouraud')
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
xlim = plt.xlim() # save the x limits of the first plot
plt.subplot(212)
plt.plot(time, y);

plt.xlim(xlim) # apply the saved limits to the second plot
plt.show()

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!