From e8dd49f4c73e9a11c9163c8b77fdd9ff7a7cb900 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 8 Feb 2013 11:30:51 -0500 Subject: [PATCH] demo_spectrogram.py: improve ticks --- interfaces/python/demo_spectrogram.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/interfaces/python/demo_spectrogram.py b/interfaces/python/demo_spectrogram.py index 4c5cac47..d85aac73 100755 --- a/interfaces/python/demo_spectrogram.py +++ b/interfaces/python/demo_spectrogram.py @@ -24,16 +24,21 @@ def get_spectrogram(filename): # plotting imshow(log10(specgram.T + .001), origin = 'bottom', aspect = 'auto', cmap=cm.gray_r) axis([0, len(specgram), 0, len(specgram[0])]) - ylabel('Frequency (Hz)') - xlabel('Time (s)') # show axes in Hz and seconds time_step = hop_s / float(samplerate) total_time = len(specgram) * time_step - ticks = 10 - xticks( arange(ticks) / float(ticks) * len(specgram), - [x * total_time / float(ticks) for x in range(ticks) ] ) - yticks( arange(ticks) / float(ticks) * len(specgram[0]), - [x * samplerate / 2. / float(ticks) for x in range(ticks) ] ) + print "total time: %0.2fs" % total_time, + print ", samplerate: %.2fkHz" % (samplerate / 1000.) + n_xticks = 10 + n_yticks = 10 + xticks_pos = [ x / float(n_xticks) * len(specgram) for x in range(n_xticks) ] + xticks_str = [ "%.2f" % (x * total_time / float(n_xticks)) for x in range(n_xticks) ] + xticks( xticks_pos , xticks_str ) + yticks_pos = [ y / float(n_yticks) * len(specgram[0]) for y in range(n_yticks) ] + yticks_str = [ "%.2f" % (y * samplerate / 2000. / float(n_yticks)) for y in range(n_yticks) ] + yticks( yticks_pos , yticks_str ) + ylabel('Frequency (kHz)') + xlabel('Time (s)') if __name__ == '__main__': if len(sys.argv) < 2: -- 2.26.2