0
私はスペクトログラムを吐き出す次のコードを見つけました。しかし、私はカラーマップやその他の方法で色をランダムに追加したいと思っています。私は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)
ありがとう!