Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda