Mercurial > hg > webaudioevaluationtool
comparison scripts/score_plot.py @ 1457:c8a9825aaa05
Merge from branch "WAC2016"
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Mon, 23 Nov 2015 09:13:12 +0000 |
parents | 04e8a9c07c7e |
children | 1b6fa37d46a4 |
comparison
equal
deleted
inserted
replaced
1456:cacd98e7e1ff | 1457:c8a9825aaa05 |
---|---|
6 import matplotlib.pyplot as plt | 6 import matplotlib.pyplot as plt |
7 import numpy as np | 7 import numpy as np |
8 import scipy as sp | 8 import scipy as sp |
9 import scipy.stats | 9 import scipy.stats |
10 | 10 |
11 # CONFIGURATION | 11 # COMMAND LINE ARGUMENTS |
12 | 12 |
13 # Which type(s) of plot do you want? | 13 #TODO: Merge, implement this functionality |
14 enable_boxplot = True # show box plot | 14 #TODO: Control by CLI arguments (plot types, save and/or show, ...) |
15 | |
16 assert len(sys.argv)<4, "score_plot takes at most 2 command line arguments\n"+\ | |
17 "Use: python score_plot.py [ratings_folder_location]."+\ | |
18 "Type 'python score_plot.py -h' for more options" | |
19 | |
20 # initialise plot types (false by default) and options | |
21 enable_boxplot = False # show box plot | |
15 enable_confidence = False # show confidence interval | 22 enable_confidence = False # show confidence interval |
16 confidence = 0.90 # confidence value (for confidence interval plot) | 23 confidence = 0.90 # confidence value (for confidence interval plot) |
17 enable_individual = False # show all individual ratings | 24 enable_individual = False # show all individual ratings |
18 show_individual = [] # show specific individuals | 25 show_individual = [] # show specific individuals (empty: show all individuals found) |
19 show_legend = False # show names of individuals | 26 show_legend = False # show names of individuals |
20 #TODO: Merge, implement this functionality | 27 |
21 #TODO: Control by CLI arguments (plot types, save and/or show, ...) | 28 # DEFAULT: Looks in 'saves/ratings/' folder from 'scripts/' folder |
22 | 29 rating_folder = "../saves/ratings/" |
23 # Enter folder where rating CSV files are (generated with score_parser.py or same format). | 30 |
24 rating_folder = '../saves/ratings/' # folder with rating csv files | 31 # XML results files location |
32 if len(sys.argv) == 1: # no extra arguments | |
33 enable_boxplot = True # show box plot | |
34 print "Use: python score_plot.py [rating folder] [plot_type] [-l/-legend]" | |
35 print "Type 'python score_plot.py -h' for help." | |
36 print "Using default path: " + rating_folder + " with boxplot." | |
37 else: | |
38 for arg in sys.argv: # go over all arguments | |
39 if arg == '-h': | |
40 # show help | |
41 #TODO: replace with contents of helpfile score_plot.info (or similar) | |
42 print "Use: python score_plot.py [rating_folder] [plot_type] [-l] [confidence]" | |
43 print " rating_folder:" | |
44 print " folder where output of 'score_parser' can be found, and" | |
45 print " where plots will be stored." | |
46 print " By default, '../saves/ratings/' is used." | |
47 print "" | |
48 print "PLOT TYPES" | |
49 print " Can be used in combination." | |
50 print " box | boxplot | -b" | |
51 print " Enables the boxplot" | |
52 print " conf | confidence | -c" | |
53 print " Enables the confidence interval plot" | |
54 print " ind | individual | -i" | |
55 print " Enables plot of individual ratings" | |
56 print "" | |
57 print "PLOT OPTIONS" | |
58 print " leg | legend | -l" | |
59 print " For individual plot: show legend with individual file names" | |
60 print " numeric value between 0 and 1, e.g. 0.95" | |
61 print " For confidence interval plot: confidence value" | |
62 assert False, ""# stop immediately after showing help #TODO cleaner way | |
63 | |
64 # PLOT TYPES | |
65 elif arg == 'box' or arg == 'boxplot' or arg == '-b': | |
66 enable_boxplot = True # show box plot | |
67 elif arg == 'conf' or arg == 'confidence' or arg == '-c': | |
68 enable_confidence = True # show confidence interval | |
69 #TODO add confidence value input | |
70 elif arg == 'ind' or arg == 'individual' or arg == '-i': | |
71 enable_individual = True # show all individual ratings | |
72 | |
73 # PLOT OPTIONS | |
74 elif arg == 'leg' or arg == 'legend' or arg == '-l': | |
75 if not enable_individual: | |
76 print "WARNING: The 'legend' option is only relevant to plots of "+\ | |
77 "individual ratings" | |
78 show_legend = True # show all individual ratings | |
79 elif arg.isdigit(): | |
80 if not enable_confidence: | |
81 print "WARNING: The numeric confidence value is only relevant when "+\ | |
82 "confidence plot is enabled" | |
83 if float(arg)>0 and float(arg)<1: | |
84 confidence = float(arg) | |
85 else: | |
86 print "WARNING: The confidence value needs to be between 0 and 1" | |
87 | |
88 # FOLDER NAME | |
89 else: | |
90 # assume it's the folder name | |
91 rating_folder = arg | |
92 | |
93 # at least one plot type should be selected: box plot by default | |
94 if not enable_boxplot and not enable_confidence and not enable_individual: | |
95 enable_boxplot = True | |
96 | |
97 # check if folder_name exists | |
98 if not os.path.exists(rating_folder): | |
99 #the file is not there | |
100 print "Folder '"+rating_folder+"' does not exist." | |
101 sys.exit() # terminate script execution | |
102 elif not os.access(os.path.dirname(rating_folder), os.W_OK): | |
103 #the file does exist but write rating_folder are not given | |
104 print "No write privileges in folder '"+rating_folder+"'." | |
105 | |
106 | |
107 # CONFIGURATION | |
25 | 108 |
26 # Font settings | 109 # Font settings |
27 font = {'weight' : 'bold', | 110 font = {'weight' : 'bold', |
28 'size' : 10} | 111 'size' : 10} |
29 plt.rc('font', **font) | 112 plt.rc('font', **font) |
129 | 212 |
130 # TITLE, AXIS LABELS AND LIMITS | 213 # TITLE, AXIS LABELS AND LIMITS |
131 plt.title(page_name) | 214 plt.title(page_name) |
132 plt.xlabel('Fragment') | 215 plt.xlabel('Fragment') |
133 plt.xlim(0, len(headerrow)+1) # only show relevant region, leave space left & right) | 216 plt.xlim(0, len(headerrow)+1) # only show relevant region, leave space left & right) |
134 plt.xticks(range(1, len(headerrow)+1), headerrow) # show fragment names | 217 plt.xticks(range(1, len(headerrow)+1), headerrow, rotation=90) # show fragment names |
135 plt.ylabel('Rating') | 218 plt.ylabel('Rating') |
136 plt.ylim(0,1) | 219 plt.ylim(0,1) |
137 | 220 |
138 | 221 |
139 | 222 |
144 # SAVE PLOT | 227 # SAVE PLOT |
145 # automatically | 228 # automatically |
146 plot_type = ("-box" if enable_boxplot else "") + \ | 229 plot_type = ("-box" if enable_boxplot else "") + \ |
147 ("-conf" if enable_confidence else "") + \ | 230 ("-conf" if enable_confidence else "") + \ |
148 ("-ind" if enable_individual else "") | 231 ("-ind" if enable_individual else "") |
149 plt.savefig(rating_folder+page_name+plot_type+".png") | 232 plt.savefig(rating_folder+page_name+plot_type+".pdf", bbox_inches='tight') |
150 plt.close() | 233 plt.close() |