annotate scripts/score_boxplot.py @ 887:13e79bef8b01

Implemeted Features #1267, #1268 and started #1266. Standardised fragment checking.
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Tue, 16 Jun 2015 16:59:08 +0100
parents a2ab04daf4c9
children 24d0d3111c00 a049c6cf7eb3
rev   line source
nicholas@886 1 import sys
nicholas@886 2 import os
nicholas@886 3 import csv
nicholas@886 4 import matplotlib.pyplot as plt
nicholas@886 5 import numpy as np
nicholas@886 6
nicholas@886 7 rating_folder = 'ratings/' # folder with rating csv files
nicholas@886 8 show_individual = 'frank'
nicholas@886 9
nicholas@886 10 # get every csv file in folder
nicholas@886 11 for file in os.listdir(rating_folder): # You have to put this in folder where rating csv files are.
nicholas@886 12 if file.endswith(".csv"):
nicholas@886 13 page_name = file[:-4] # file name (without extension) is page ID
nicholas@886 14
nicholas@886 15 # get header
nicholas@886 16 with open(rating_folder+file, 'r') as readfile: # read this csv file
nicholas@886 17 filereader = csv.reader(readfile, delimiter=',')
nicholas@886 18 headerrow = filereader.next() # use headerrow as X-axis
nicholas@886 19 headerrow = headerrow[1:]
nicholas@886 20
nicholas@886 21 # read ratings into matrix
nicholas@886 22 ratings = np.loadtxt(open(rating_folder+file,"rb"),
nicholas@886 23 delimiter=",",
nicholas@886 24 skiprows=1,
nicholas@886 25 usecols=range(1,len(headerrow)+1)
nicholas@886 26 )
nicholas@886 27
nicholas@886 28 # draw boxplot
nicholas@886 29 plt.boxplot(ratings)
nicholas@886 30
nicholas@886 31 # add rating of individual(s)
nicholas@886 32 with open(rating_folder+file, 'r') as readfile: # read this csv file
nicholas@886 33 filereader = csv.reader(readfile, delimiter=',')
nicholas@886 34 headerrow = filereader.next() # use headerrow as X-axis
nicholas@886 35 headerrow = headerrow[1:]
nicholas@886 36 markerlist = ["x", ".", "o", "*", "+", "v", ">", "<", "8", "s", "p"]
nicholas@886 37 increment = 0
nicholas@886 38 linehandles = []
nicholas@886 39 legendnames = []
nicholas@886 40 for row in filereader:
nicholas@886 41 subject_id = row[0][:-4]
nicholas@886 42 if subject_id in show_individual:
nicholas@886 43 plothandle, = plt.plot(range(1,len(row)), # x-values
nicholas@886 44 row[1:], # y-values: csv values except subject name
nicholas@886 45 color='k',
nicholas@886 46 marker=markerlist[increment%len(markerlist)],
nicholas@886 47 markersize=10,
nicholas@886 48 linestyle='None',
nicholas@886 49 label=subject_id
nicholas@886 50 )
nicholas@886 51 increment += 1 # increase counter
nicholas@886 52 linehandles.append(plothandle)
nicholas@886 53 legendnames.append(subject_id)
nicholas@886 54 plt.legend(linehandles, legendnames,
nicholas@886 55 loc='upper right',
nicholas@886 56 bbox_to_anchor=(1.1, 1), borderaxespad=0.)
nicholas@886 57
nicholas@886 58
nicholas@886 59 plt.xlabel('Fragment')
nicholas@886 60 plt.title('Box plot '+page_name)
nicholas@886 61 plt.xlim(0, len(headerrow)+1) # only show relevant region, leave space left & right)
nicholas@886 62 plt.xticks(range(1, len(headerrow)+1), headerrow) # show fragment names
nicholas@886 63
nicholas@886 64 plt.ylabel('Rating')
nicholas@886 65 plt.ylim(0,1)
nicholas@886 66
nicholas@886 67 #plt.show() # show plot
nicholas@886 68 #exit()
nicholas@886 69
nicholas@886 70 plt.savefig(rating_folder+page_name+"-box.png")
nicholas@886 71 plt.close()