Mercurial > hg > webaudioevaluationtool
comparison scripts/score_individual.py @ 148:c5f6608e0b16
Score plotting: plot of individual scores and box plot (with optional overlay of selected individual ratings). Uses CSV files as produced by 'score_boxplot.py'.
author | Brecht De Man <b.deman@qmul.ac.uk> |
---|---|
date | Sun, 31 May 2015 18:03:13 +0100 |
parents | |
children | 97ebdb6b266a |
comparison
equal
deleted
inserted
replaced
147:927d05a43a70 | 148:c5f6608e0b16 |
---|---|
1 import sys | |
2 import os | |
3 import csv | |
4 import matplotlib.pyplot as plt | |
5 | |
6 rating_folder = 'ratings/' # folder with rating csv files | |
7 | |
8 colormap = ['b', 'r', 'g', 'c', 'm', 'y', 'k'] # colormap for to cycle through | |
9 markerlist = ["x", ".", "o", "*", "+", "v", ">", "<", "8", "s", "p"] | |
10 | |
11 # get every csv file in folder | |
12 for file in os.listdir(rating_folder): # You have to put this in folder where rating csv files are. | |
13 if file.endswith(".csv"): | |
14 page_name = file[:-4] # file name (without extension) is page ID | |
15 | |
16 with open(rating_folder+file, 'r') as readfile: # read this csv file | |
17 filereader = csv.reader(readfile, delimiter=',') | |
18 headerrow = filereader.next() # use headerrow as X-axis | |
19 headerrow = headerrow[1:] | |
20 | |
21 | |
22 increment = 0 | |
23 linehandles = [] | |
24 legendnames = [] | |
25 for row in filereader: | |
26 subject_id = row[0][:-4] | |
27 plothandle, = plt.plot(range(1,len(row)), # x-values | |
28 row[1:], # y-values: csv values except subject name | |
29 color=colormap[increment%len(colormap)], | |
30 marker=markerlist[increment%len(markerlist)], | |
31 markersize=10, | |
32 linestyle='None', | |
33 label=subject_id | |
34 ) | |
35 increment += 1 # increase counter | |
36 linehandles.append(plothandle) | |
37 legendnames.append(subject_id) | |
38 | |
39 | |
40 plt.xlabel('Fragment') | |
41 plt.title('Individual ratings '+page_name) | |
42 plt.xlim(0, len(headerrow)+1) # only show relevant region, leave space left & right) | |
43 plt.xticks(range(1, len(headerrow)+1), headerrow) # show fragment names | |
44 | |
45 plt.ylabel('Rating') | |
46 plt.ylim(0,1) | |
47 | |
48 plt.legend(linehandles, legendnames, | |
49 loc='upper right', | |
50 bbox_to_anchor=(1.1, 1), borderaxespad=0.) | |
51 | |
52 #TODO Put legend outside of box | |
53 #TODO Why two markers in legend? | |
54 | |
55 plt.show() | |
56 #exit() | |
57 | |
58 #TODO Save output automatically |