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. 
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()