Mercurial > hg > webaudioevaluationtool
changeset 285:037393e98cd9
Scripts: timeline with rectangles (accurate start and end, customisable width); timeline and score plots to PDF by default.
author | Brecht De Man <b.deman@qmul.ac.uk> |
---|---|
date | Tue, 11 Aug 2015 11:06:55 +0200 |
parents | f32e58635091 |
children | 4a8b99d1b032 |
files | .hgignore scripts/score_plot.py scripts/timeline_view.py |
diffstat | 3 files changed, 38 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Tue Aug 11 10:15:17 2015 +0200 +++ b/.hgignore Tue Aug 11 11:06:55 2015 +0200 @@ -30,4 +30,5 @@ saves/*.csv saves/*/*.csv saves/*/*.png -saves/*/*.xml \ No newline at end of file +saves/*/*.xml +saves/ratings/*.pdf \ No newline at end of file
--- a/scripts/score_plot.py Tue Aug 11 10:15:17 2015 +0200 +++ b/scripts/score_plot.py Tue Aug 11 11:06:55 2015 +0200 @@ -85,11 +85,10 @@ else: print "WARNING: The confidence value needs to be between 0 and 1" - # FOLDER NAME - else: - # assume it's the folder name - rating_folder = arg - #TODO try it exists, otherwise show exception + # FOLDER NAME + else: + # assume it's the folder name + rating_folder = arg # at least one plot type should be selected: box plot by default if not enable_boxplot and not enable_confidence and not enable_individual: @@ -230,5 +229,5 @@ plot_type = ("-box" if enable_boxplot else "") + \ ("-conf" if enable_confidence else "") + \ ("-ind" if enable_individual else "") - plt.savefig(rating_folder+page_name+plot_type+".png") + plt.savefig(rating_folder+page_name+plot_type+".pdf", bbox_inches='tight') plt.close()
--- a/scripts/timeline_view.py Tue Aug 11 10:15:17 2015 +0200 +++ b/scripts/timeline_view.py Tue Aug 11 11:06:55 2015 +0200 @@ -4,6 +4,7 @@ import os # list files in directory import sys # command line arguments import matplotlib.pyplot as plt # plots +import matplotlib.patches as patches # rectangles # COMMAND LINE ARGUMENTS @@ -17,7 +18,7 @@ print "Using default path: " + folder_name elif len(sys.argv) == 2: folder_name = sys.argv[1] # First command line argument is folder - + # check if folder_name exists if not os.path.exists(folder_name): #the file is not there @@ -41,9 +42,16 @@ # Colormap for to cycle through colormap = ['b', 'r', 'g', 'c', 'm', 'y', 'k'] -# x-axis shows time per audioholder, not total test time +# if enabled, x-axis shows time per audioholder, not total test time show_audioholder_time = True +# bar height (<1 to avoid overlapping) +bar_height = 0.6 + +# figure size +fig_width = 25 +fig_height = 5 + # CODE @@ -82,6 +90,16 @@ increment = 0 # increased for every new audioelement audioelements_names = [] # store names of audioelements + # set plot parameters + plt.title('Timeline ' + file + ": "+page_name) + plt.xlabel('Time [seconds]') + plt.ylabel('Fragment') + plt.ylim(0, N_audioelements+1) + + # get axes handle + fig = plt.figure(figsize=(fig_width, fig_height)) + ax = fig.add_subplot(111) #, aspect='equal' + # for page [page_name], print comments related to fragment [id] for tuple in data: audioelement = tuple[1] @@ -96,22 +114,25 @@ start_time = float(event.find('testtime').get('start')) stop_time = float(event.find('testtime').get('stop')) # event lines: - plt.plot([start_time-time_offset, start_time-time_offset], # x-values + ax.plot([start_time-time_offset, start_time-time_offset], # x-values [0, N_audioelements+1], # y-values color='k' ) - plt.plot([stop_time-time_offset, stop_time-time_offset], # x-values + ax.plot([stop_time-time_offset, stop_time-time_offset], # x-values [0, N_audioelements+1], # y-values color='k' ) # plot time: - plt.plot([start_time-time_offset, stop_time-time_offset], # x-values - [N_audioelements-increment, N_audioelements-increment], # y-values - color=colormap[increment%len(colormap)], - linewidth=6 + ax.add_patch( + patches.Rectangle( + (start_time-time_offset, N_audioelements-increment-bar_height/2), # (x, y) + stop_time - start_time, # width + bar_height, # height + color=colormap[increment%len(colormap)] # colour ) + ) - increment+=1 + increment+=1 # to next audioelement # subtract total audioholder length from subsequent audioholder event times audioholder_time = audioholder.find("./metric/metricresult/[@id='testTime']") @@ -121,11 +142,6 @@ #TODO: if 'nonsensical' or unknown: dashed line until next event #TODO: Vertical lines for fragment looping point - plt.title('Timeline ' + file) #TODO add song too - plt.xlabel('Time [seconds]') - plt.ylabel('Fragment') - plt.ylim(0, N_audioelements+1) - #y-ticks: fragment IDs, top to bottom plt.yticks(range(N_audioelements, 0, -1), audioelements_names) # show fragment names @@ -133,5 +149,5 @@ #plt.show() # uncomment to show plot; comment when just saving #exit() - plt.savefig(timeline_folder+subject_id+"-"+page_name+".png") + plt.savefig(timeline_folder+subject_id+"-"+page_name+".pdf", bbox_inches='tight') plt.close() \ No newline at end of file