在Pylab中,
我想要生成声谱图(瞬时功率由
specgram()
函数会为给定的振幅列表创建一个声谱图,并自动创建一个窗口来显示声谱图。我想要生成声谱图(瞬时功率由
Pxx
给出),对其进行边缘检测并绘制结果。(Pxx, freqs, bins, im) = pylab.specgram( self.data, Fs=self.rate, ...... )
问题在于,每当我尝试使用imshow
甚至NonUniformImage
来绘制修改后的Pxx
时,都会遇到以下错误消息。
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/image.py:336: UserWarning: Images are not supported on non-linear axes. warnings.warn("Images are not supported on non-linear axes.")
例如,我正在处理的代码的一部分如下所示:
# how many instantaneous spectra did we calculate
(numBins, numSpectra) = Pxx.shape
# how many seconds in entire audio recording
numSeconds = float(self.data.size) / self.rate
ax = fig.add_subplot(212)
im = NonUniformImage(ax, interpolation='bilinear')
x = np.arange(0, numSpectra)
y = np.arange(0, numBins)
z = Pxx
im.set_data(x, y, z)
ax.images.append(im)
ax.set_xlim(0, numSpectra)
ax.set_ylim(0, numBins)
ax.set_yscale('symlog') # see http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_yscale
ax.set_title('Spectrogram 2')
实际问题
如何在matplotlib/pylab中使用对数y轴绘制类似图像的数据?
specgram
返回的原始数据。它实际绘制的是10 * np.log10(Pxx)
。我马上会添加一个例子。 - Joe Kington