title: Wrong spectrogram when using scipy.signal.spectrogram
body: <p>When I use the plt.specgram from matplotlib by using the following code, the spectrogram generated is correct</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from scipy import signal
  from scipy.io import wavfile
  import numpy as np
  
  sample_rate, samples = wavfile.read('.\\Wav\\test.wav')
  
  Pxx, freqs, bins, im = plt.specgram(samples[:,1], NFFT=1024, Fs=44100, noverlap=900)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/UH5CL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UH5CL.png" alt="spectrogram generated by using matplotlib"></a></p>
  
  <p>However, if I generate the spectrogram by using the example code given by in the <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html" rel="noreferrer">scipy page</a> with the following code, I get something like this:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from scipy import signal
  from scipy.io import wavfile
  import numpy as np
  
  sample_rate, samples = wavfile.read('.\\Wav\\test.wav')
  
  frequencies, times, spectrogram = signal.spectrogram(samples[:,1],sample_rate,nfft=1024,noverlap=900, nperseg=1024)
  
  plt.pcolormesh(times, frequencies, spectrogram)
  plt.ylabel('Frequency [Hz]')
  plt.xlabel('Time [sec]')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/5OZ1f.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5OZ1f.png" alt="enter image description here"></a></p>
  
  <p>To debug what's going on, I tried using the <code>Pxx</code>, <code>freqs</code>, <code>bins</code>, generated by the first method, and then use the second method to plot out the data:</p>
  
  <pre><code>plt.pcolormesh(bins, freqs, Pxx)
  plt.ylabel('Frequency [Hz]')
  plt.xlabel('Time [sec]')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/rBl6A.png" rel="noreferrer"><img src="https://i.stack.imgur.com/rBl6A.png" alt="enter image description here"></a></p>
  
  <p>The graph generated is almost the same as the graph generated by the second method.
  So, it seems there is no problem with the <code>scipy.signal.spectrogram</code> after all. The problem is the way that we plot the graph. I wonder if <code>plt.pcolormesh</code> is the correct way to plot the spectrogram despite the fact that this method is suggested in the <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html" rel="noreferrer">scipy document</a> </p>
  
  <p>A similar question has been asked <a href="https://stackoverflow.com/questions/48598994/scipy-signal-spectrogram-compared-to-matplotlib-pyplot-specgram">here</a>, but there's no solution to the question yet.</p>