annotate scripts/score_individual.py @ 923:7a7a72880996

Merge from the default branch
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Tue, 02 Jun 2015 11:24:23 +0100
parents 533d51508e93
children 4a0bfa7bef24
rev   line source
n@921 1 import sys
n@921 2 import os
n@921 3 import csv
n@921 4 import matplotlib.pyplot as plt
n@921 5
n@921 6 rating_folder = 'ratings/' # folder with rating csv files
n@921 7
n@921 8 colormap = ['b', 'r', 'g', 'c', 'm', 'y', 'k'] # colormap for to cycle through
n@921 9 markerlist = ["x", ".", "o", "*", "+", "v", ">", "<", "8", "s", "p"]
n@921 10
n@921 11 # get every csv file in folder
n@921 12 for file in os.listdir(rating_folder): # You have to put this in folder where rating csv files are.
n@921 13 if file.endswith(".csv"):
n@921 14 page_name = file[:-4] # file name (without extension) is page ID
n@921 15
n@921 16 with open(rating_folder+file, 'r') as readfile: # read this csv file
n@921 17 filereader = csv.reader(readfile, delimiter=',')
n@921 18 headerrow = filereader.next() # use headerrow as X-axis
n@921 19 headerrow = headerrow[1:]
n@921 20
n@921 21
n@921 22 increment = 0
n@921 23 linehandles = []
n@921 24 legendnames = []
n@921 25 for row in filereader:
n@921 26 subject_id = row[0][:-4]
n@921 27 plothandle, = plt.plot(range(1,len(row)), # x-values
n@921 28 row[1:], # y-values: csv values except subject name
n@921 29 color=colormap[increment%len(colormap)],
n@921 30 marker=markerlist[increment%len(markerlist)],
n@921 31 markersize=10,
n@921 32 linestyle='None',
n@921 33 label=subject_id
n@921 34 )
n@921 35 increment += 1 # increase counter
n@921 36 linehandles.append(plothandle)
n@921 37 legendnames.append(subject_id)
n@921 38
n@921 39
n@921 40 plt.xlabel('Fragment')
n@921 41 plt.title('Individual ratings '+page_name)
n@921 42 plt.xlim(0, len(headerrow)+1) # only show relevant region, leave space left & right)
n@921 43 plt.xticks(range(1, len(headerrow)+1), headerrow) # show fragment names
n@921 44
n@921 45 plt.ylabel('Rating')
n@921 46 plt.ylim(0,1)
n@921 47
n@921 48 plt.legend(linehandles, legendnames,
n@921 49 loc='upper right',
n@921 50 bbox_to_anchor=(1.1, 1), borderaxespad=0.)
n@921 51
n@921 52 #TODO Put legend outside of box
n@921 53 #TODO Why two markers in legend?
n@921 54
n@921 55 plt.show()
n@921 56 #exit()
n@921 57
n@921 58 #TODO Save output automatically
n@921 59