当我试图了解imshow
和pcolormesh
之间的区别时,我遇到了一个无法确定原因的问题。
例如,我有一个频率为10kHz的正弦波
import numpy as np
import matplotlib.pyplot as plt
from scipy import fft
f = 10000 # Frequency, in cycles per second, or Hertz
fs = 44100 # Sampling rate, or number of measurements per second
t = np.linspace(0, 5, 5 * fs, endpoint=False)
X = np.sin(f * 2 * np.pi * t)
在此信号上应用fft
会得到频谱图Xs
window_size = 2048 # 2048-sample fourier windows
stride = 512 # 512 samples between windows
wps = fs/float(512) # ~86 windows/second
Xs = np.empty([int(2*wps),2048])
for i in range(Xs.shape[0]):
Xs[i] = np.abs(fft(X[i*stride:i*stride+window_size]))
现在,我想用Xs
和imshow
绘制频谱图pcolormesh
。
fig = plt.figure(figsize=(20,7))
plt.imshow(Xs.T,aspect='auto',cmap='seismic')
plt.gca().invert_yaxis()
plt.colorbar()
fig = plt.figure(figsize=(20,7))
plt.pcolormesh(Xs.T,cmap='seismic')
plt.colorbar()
它们为什么不同?