如何修复:MatplotlibDeprecationWarning:当 X 和 Y 具有与 C 相同的尺寸时,阴影='平坦' 自 3.3 起已弃用

Roo*_*prr 7 python speech-recognition matplotlib wav spectrogram

我是 python 编程的菜鸟,但在尝试从 RAVDESS 数据集 wav 文件绘制频谱图时,我一直在与这些错误作斗争。这是代码;

`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()`
Run Code Online (Sandbox Code Playgroud)

这是错误

<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)
Run Code Online (Sandbox Code Playgroud)

抱歉,我无法更好地解释这些错误,但我对此很陌生,任何帮助都会很棒。

小智 7

添加shading='auto' 将解决此问题。

所以代码应该是 plt.pcolormesh(times, frequencies, spectrogram,shading='auto' )


小智 3

我解决了更改 rcparams: 的问题plt.rcParams['pcolor.shading'] ='nearest'。希望这会对某人有所帮助。