Changeset 4db10ad
 Timestamp:
 Feb 9, 2013, 10:48:47 AM (7 years ago)
 Branches:
 feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
 Children:
 fa11ce0
 Parents:
 c3d286c
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

interfaces/python/demo_spectrogram.py
rc3d286c r4db10ad 32 32 n_xticks = 10 33 33 n_yticks = 10 34 xticks_pos = [ x / float(n_xticks) * len(specgram) for x in range(n_xticks) ] 35 xticks_str = [ "%.2f" % (x * total_time / float(n_xticks)) for x in range(n_xticks) ] 36 xticks( xticks_pos , xticks_str ) 37 yticks_pos = [ y / float(n_yticks) * len(specgram[0]) for y in range(n_yticks) ] 38 yticks_str = [ "%.2f" % (y * samplerate / 2000. / float(n_yticks)) for y in range(n_yticks) ] 39 yticks( yticks_pos , yticks_str ) 34 35 def get_rounded_ticks( top_pos, step, n_ticks ): 36 top_label = top_pos * step 37 # get the first label 38 ticks_first_label = top_pos * step / n_ticks 39 # round to the closest .1 40 ticks_first_label = round ( ticks_first_label * 10. ) / 10. 41 # compute all labels from the first rounded one 42 ticks_labels = [ ticks_first_label * n for n in range(n_ticks) ] + [ top_label ] 43 # get the corresponding positions 44 ticks_positions = [ ticks_labels[n] / step for n in range(n_ticks) ] + [ top_pos ] 45 # convert to string 46 ticks_labels = [ "%.1f" % x for x in ticks_labels ] 47 # return position, label tuple to use with x/yticks 48 print ticks_positions, ticks_labels 49 return ticks_positions, ticks_labels 50 51 # apply to the axis 52 xticks( *get_rounded_ticks ( len(specgram), time_step, n_xticks ) ) 53 yticks( *get_rounded_ticks ( len(specgram[0]), (samplerate / 2. / 1000.) / len(specgram[0]), n_yticks ) ) 40 54 ylabel('Frequency (kHz)') 41 55 xlabel('Time (s)')
Note: See TracChangeset
for help on using the changeset viewer.