I’d like to create a campbell diagram (sound pressure level over time and frequency) with python. That works fine as long as the y-axis that shows the frequency is linear.
When I switch to log (which is industry standard), the result looks unexpected. No matter what I enter for plt.ylim, the diagram looks the same with the distorted y-axis.
Since it looks the same both on my Win10 business box as well as on my private linux laptop, I assume that I am missing s.th. Any hint is greatly appreciated.
from scipy import signal import numpy as np import sounddevice as sd import matplotlib.pyplot as plt fs=44100 # Samplerate duration = 2 # seconds leng=duration*fs # Get a signal from the default microphone myrec = sd.rec(int(leng), samplerate=fs, channels=1, blocking=True) myrec=myrec.flatten() f, t, Zxx=signal.stft(myrec,fs,window='hann',nperseg=256) plt.pcolormesh(t, f, np.abs(Zxx), shading='gouraud') plt.title('Campbell') plt.ylabel('frequency [Hz]') # Log plot - for the linear plot that looks ok skip the next two lines plt.ylim=(10,10000) plt.yscale('log') # plt.xlabel('time [s]') plt.show()
Not as expected: