title: scipy.signal.spectrogram compared to matplotlib.pyplot.specgram
body: <p>The following code generates a spectrogram using either <code>scipy.signal.spectrogram</code> or <code>matplotlib.pyplot.specgram</code>.</p>
  
  <p>The color contrast of the <code>specgram</code> function is, however, rather low.
  Is there a way to increase it?</p>
  
  <pre><code>import numpy as np
  from scipy import signal
  import matplotlib.pyplot as plt
  
  # Generate data
  fs = 10e3
  N = 5e4
  amp = 4 * np.sqrt(2)
  noise_power = 0.01 * fs / 2
  time = np.arange(N) / float(fs)
  mod = 800*np.cos(2*np.pi*0.2*time)
  carrier = amp * np.sin(2*np.pi*time + mod)
  noise = np.random.normal(scale=np.sqrt(noise_power), size=time.shape)
  noise *= np.exp(-time/5)
  x = carrier + noise
  </code></pre>
  
  <p>Using <code>matplotlib.pyplot.specgram</code> gives the following result:</p>
  
  <pre><code>Pxx, freqs, bins, im = plt.specgram(x, NFFT=1028, Fs=fs)
  x1, x2, y1, y2 = plt.axis()
  plt.axis((x1, x2, 0, 200))
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/B6XZn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/B6XZn.png" alt="Image obtained with matplotlib.pyplot.specgram"></a></p>
  
  <p>Using <code>scipy.signal.spectrogram</code> gives the following plot</p>
  
  <pre><code>f, t, Sxx = signal.spectrogram(x, fs, nfft=1028)
  plt.pcolormesh(t, f[0:20], Sxx[0:20])
  plt.ylabel('Frequency [Hz]')
  plt.xlabel('Time [sec]')
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/SmooK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SmooK.png" alt="Image obtained with scipy.signal.spectrogram"></a></p>
  
  <p>Both functions seem to use the 'jet' colormap.</p>
  
  <p>I would also be generally interested in the difference between the two functions. Although they do something similar, they are obviously not identical.</p>