annotate scripts/score_individual.py @ 2017:4a14c8a65af2

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