annotate scripts/score_individual.py @ 150:97ebdb6b266a

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