my goal is to generate scalogram from .wav file and save as jpg or png format,i used following code :

import cv2
from scipy import signal
import numpy as np
import pywt
import matplotlib.pyplot as plt
import librosa
y,sr =librosa.load("genres_original/classical/classical.00000.wav")
width =np.arange(1,31)
# cwtmatr =signal.cwt(y,signal.gau,width)
coef, freqs=pywt.cwt(y,width,'morl')
# plt.imshow(abs(cwtmatr), cmap='plasma', aspect='auto')
# plt.matshow(abs(coef))
plt.figure(figsize=(15, 10))
plt.imshow(abs(coef), extent=(0, 200, 30, 1), interpolation='bilinear', cmap='bone',
           aspect='auto', vmax=abs(coef).max(), vmin=abs(coef).max())
plt.yticks(np.arange(1, 31, 1))
plt.xticks(np.arange(0, 31, 1))
           # vmax=abs(cwtmatr).max(),
           # vmin=-abs(cwtmatr).min()) # finally we plot the scalogram

but when i am running this code, getting blanck image enter image description here

could you tell me please what is reason? what part am i missing here?


1 Answer 1


I didn't try to run your example locally but try something like this using plt.pcolormesh :

    plt.pcolormesh(t, freqs, np.abs(coefs), shading='auto')
    plt.yticks(np.arange(min(freqs), max(freqs)+1, 3))

I've only used plt.imshow with real images so I don't know if that function is making some assumptions on what it will receive as an input. To plot a scalogram plt.pcolormesh can do the job pretty quickly.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.