Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOW TO FIX: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3

I'm a rookie to python programming but I have been battling these errors for the longest when trying to plot spectrograms from the RAVDESS dataset wav files. This is the code;

`for file in range(0 , len(listOfFiles) , 1):
    windows_size = 20
    sample_rate , samples = wavfile.read(listOfFiles[file])
    nperseg = int(round(20 * sample_rate / 1e3))   
    frequencies , times, spectrogram = signal.spectrogram(samples, sample_rate) 
    plt.pcolormesh(times, frequencies, spectrogram)
    plt.imshow(spectrogram)
    plt.ylabel('Frequency [Hz]')
    plt.xlabel('Time [sec]')
    plt.show()`

Here are the errors

<ipython-input-16-dc119f345487>:14: WavFileWarning: Chunk (non-data) not understood, skipping it.
  sample_rate , samples = wavfile.read(listOfFiles[file])
<ipython-input-16-dc119f345487>:14: WavFileWarning: Incomplete chunk ID: b'\x00', ignoring it.
  sample_rate , samples = wavfile.read(listOfFiles[file])
<ipython-input-16-dc119f345487>:17: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3.  Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading'].  This will become an error two minor releases later.
  plt.pcolormesh(times, frequencies, spectrogram)

Sorry that I cant explain the errors better but I'm new to this, any kinda help would be amazing.

like image 495
RookieDevlprr Avatar asked Jan 19 '21 21:01

RookieDevlprr


2 Answers

Add shading='auto' will resolve this.

So the code should be plt.pcolormesh(times, frequencies, spectrogram,shading='auto' )

like image 170
Ray Ronnaret Avatar answered Nov 14 '22 23:11

Ray Ronnaret


I solved the issue changing my rcparams: plt.rcParams['pcolor.shading'] ='nearest'. Hope that this will help someone.

like image 3
fedeircoP Avatar answered Nov 15 '22 00:11

fedeircoP