title: scipy spectrogram with logarithmic frequency axis?
body: <p>Playing with scipy.signal.spectrogram. Works fine for what it is.</p>
  
  <pre><code>from scipy.io import wavfile
  from scipy import signal
  import numpy as np
  import matplotlib.pyplot as plt
  
  sf, audio = wavfile.read('serious.wav')
  sig = np.mean(audio, axis=1)
  f, t, Sxx = signal.spectrogram(sig, sf, scaling='spectrum')
  
  plt.pcolormesh(t, f, np.log10(Sxx))
  plt.ylabel('f [Hz]')
  plt.xlabel('t [sec]')
  plt.show()
  </code></pre>
  
  <p>This is the result:</p>
  
  <p><a href="https://i.stack.imgur.com/F11DY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F11DY.png" alt="spectrogram"></a></p>
  
  <p>But the frequency axis is linear. For audio this is not often desirable - at any rate, it's not what I want.</p>
  
  <p>Is there a way to coax scipy.signal.spectrogram to output a logarithmic frequency scale?</p>
  
  <p>If this is not doable with scipy, could you recommend an equally simple approach to obtain this result?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> The problem is not in the way the image is displayed. The problem is in the way the data is generated by <code>signal.spectrogram()</code></p>
  
  <p>I've changed the code like this:</p>
  
  <pre><code>plt.pcolormesh(t, f, np.log10(Sxx))
  plt.ylabel('f [Hz]')
  plt.xlabel('t [sec]')
  plt.yscale('log')
  plt.savefig('spec.png')
  plt.show()
  </code></pre>
  
  <p>And now the image looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/QOB5p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QOB5p.png" alt="spectrogram"></a></p>
  
  <p>The f vector (generated by <code>signal.spectrogram()</code>) looks like this:</p>
  
  <pre><code>array([    0.      ,   172.265625,   344.53125 ,   516.796875,
           689.0625  ,   861.328125,  1033.59375 ,  1205.859375,
          1378.125   ,  1550.390625,  1722.65625 ,  1894.921875,
          2067.1875  ,  2239.453125,  2411.71875 ,  2583.984375,
  ...
         19982.8125  , 20155.078125, 20327.34375 , 20499.609375,
         20671.875   , 20844.140625, 21016.40625 , 21188.671875,
         21360.9375  , 21533.203125, 21705.46875 , 21877.734375,
         22050.      ])
  </code></pre>
  
  <p>That's a linear distribution. I need far more points in the lower end, and far fewer at the top end.</p>