如何修复:MatplotlibDeprecationWarning:shading='flat'当X和Y的尺寸与C的尺寸相同时,自3.3版以来已不推荐使用

2024-09-30 23:40:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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()`

以下是错误

<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)

很抱歉,我不能更好地解释错误,但我是新手,任何形式的帮助都会令人惊讶


Tags: samplereadinputrate错误ipythonpltfile
3条回答

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

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

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

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

所以代码应该是

plt.pcolormesh(times, frequencies, spectrogram,shading='auto' )

相关问题 更多 >