title: Matplotlib spectrogram intensity legend (colorbar)
body: <p>I'm using matplotlib's <code>specgram</code> function to generate a spectrogram. I've attempted to include a colorbar off to the right of the spectrogram to give an indication of dB-to-color-mapping.</p>
  
  <p>For some reason though, the dB indicated by the colorbar do not make sense.</p>
  
  <p>Perhaps I've not generated the colorbar correctly? Perhaps there is some parameter that I need to pass to specgram?</p>
  
  <p>The signal I'm generating is a 1Khz, 2Vpp sine sampled at 32Khz.</p>
  
  <p>I'm expecting that the dark red peak on the spectrogram corresponds to 0dB (Meaning that +1V is my reference)</p>
  
  <p>Anybody have any idea what is wrong with my approach?</p>
  
  <pre><code>def plot_specgram(data, title='', x_label='', y_label='', fig_size=None):
      fig = plt.figure()
      if fig_size != None:
          fig.set_size_inches(fig_size[0], fig_size[1])
      ax = fig.add_subplot(111)
      ax.set_title(title)
      ax.set_xlabel(x_label)
      ax.set_ylabel(y_label)
      pxx,  freq, t, cax = plt.specgram(data, Fs=32000)
      fig.colorbar(cax).set_label('Intensity [dB]')
  
  plot_specgram(a,title='Spectrogram', x_label='time (in seconds)', y_label='frequency', fig_size=(14,8))
  </code></pre>
  
  <p>This is what I get as resulting spectrogram:</p>
  
  <p><img src="https://i.stack.imgur.com/eI8zv.png" alt="resulting plot"></p>