Python 如何拉伸y轴

Python 如何拉伸y轴,python,matplotlib,Python,Matplotlib,我正试图用Matplotlib可视化光谱图 temp = total_slices[subject_num, trail_num, :, :] spectrum = np.fft.fft(temp, axis=0)[:M // 2 + 1:-1] spectrum = np.abs(spectrum) print(spectrum.shape) # recording length: L = remaining_samples_from_rec[subject_num, trail_num,

我正试图用Matplotlib可视化光谱图

temp = total_slices[subject_num, trail_num, :, :]

spectrum = np.fft.fft(temp, axis=0)[:M // 2 + 1:-1]
spectrum = np.abs(spectrum)
print(spectrum.shape)

# recording length:
L = remaining_samples_from_rec[subject_num, trail_num, :].shape[0]
# rate is the sampling frequency or sampling_rate
rate = sampling_rate

S = np.abs(spectrum)
S = 10 * np.log10(S / np.max(S))
print(S.shape, type(S))

fig, ax = plt.subplots(figsize=(4.8, 2.4))


ax.set_ylabel('Frequency [kHz]')
ax.set_xlabel('Time [ms]');

dir_path = 'PaperFigures/steady/' + col + '/' + vowel
if not os.path.exists(dir_path):
    os.makedirs(dir_path)

xticks = np.linspace(start=0, stop=spectrum.shape[1], num=10, dtype=np.int32)
xticks_labels = [str(x) for x in np.linspace(start=0, stop=300, num=10, dtype=np.int32)]

ax.set_xticks(xticks)
ax.set_xticklabels(xticks_labels, rotation=45)

ax.imshow(S, origin='lower', cmap='viridis')
fig.savefig(dir_path + '/subject_{}_trail_{}.png'.format(subject_num, trail_num))
因此,我得到的是:

我想知道如何使y轴变宽。我试过
fig,ax=plt.subplot(figsize=(4.8,20.4))
但没有成功。。我试着设置yticks和yticks_标签,但也没用

非常感谢您的帮助


imshow(…,aspect=“auto”)
或使用pcolormesh。
imshow(…,aspect=“auto”)
或使用pcolormesh。