【发布时间】:2018-05-28 02:01:47
【问题描述】:
所以我发现下面的代码会吐出一个频谱图。但是,我想通过颜色图或其他方法为其添加一些随机颜色。我已经阅读了 cmap 文档,但没有理解任何内容。
代码:
import matplotlib.pyplot as plt
from scipy.io import wavfile
def graph_spectrogram(wav_file):
rate, data = get_wav_info(wav_file)
nfft = 256
fs = 256
pxx, freqs, bins, im = plt.specgram(data, nfft,fs)
plt.axis('off')
plt.savefig('sp_xyz.png',
dpi=100, # Dots per inch
frameon='false',
aspect='normal',
bbox_inches='tight',
pad_inches=0)
plt.show()
def get_wav_info(wav_file):
rate, data = wavfile.read(wav_file)
return rate, data
if __name__ == '__main__': # Main function
wav_file = 'song.wav'
graph_spectrogram(wav_file)
提前感谢您的帮助!
【问题讨论】:
标签: python matplotlib colors colormap spectrogram