annotate scripts/score_boxplot.py @ 174:b19712875046

Feature #1232: <commentBoxPrefix> node now in <interface> of audioHolder. If not specified, default is 'Comment on track'
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 04 Jun 2015 10:06:42 +0100
parents 97ebdb6b266a
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 import numpy as np
b@148 6
b@148 7 rating_folder = 'ratings/' # folder with rating csv files
b@148 8 show_individual = 'frank'
b@148 9
b@148 10 # get every csv file in folder
b@148 11 for file in os.listdir(rating_folder): # You have to put this in folder where rating csv files are.
b@148 12 if file.endswith(".csv"):
b@148 13 page_name = file[:-4] # file name (without extension) is page ID
b@148 14
b@148 15 # get header
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 # read ratings into matrix
b@148 22 ratings = np.loadtxt(open(rating_folder+file,"rb"),
b@148 23 delimiter=",",
b@148 24 skiprows=1,
b@148 25 usecols=range(1,len(headerrow)+1)
b@148 26 )
b@148 27
b@148 28 # draw boxplot
b@148 29 plt.boxplot(ratings)
b@148 30
b@148 31 # add rating of individual(s)
b@148 32 with open(rating_folder+file, 'r') as readfile: # read this csv file
b@148 33 filereader = csv.reader(readfile, delimiter=',')
b@148 34 headerrow = filereader.next() # use headerrow as X-axis
b@148 35 headerrow = headerrow[1:]
b@148 36 markerlist = ["x", ".", "o", "*", "+", "v", ">", "<", "8", "s", "p"]
b@148 37 increment = 0
b@148 38 linehandles = []
b@148 39 legendnames = []
b@148 40 for row in filereader:
b@148 41 subject_id = row[0][:-4]
b@148 42 if subject_id in show_individual:
b@148 43 plothandle, = plt.plot(range(1,len(row)), # x-values
b@148 44 row[1:], # y-values: csv values except subject name
b@148 45 color='k',
b@148 46 marker=markerlist[increment%len(markerlist)],
b@148 47 markersize=10,
b@148 48 linestyle='None',
b@148 49 label=subject_id
b@148 50 )
b@148 51 increment += 1 # increase counter
b@148 52 linehandles.append(plothandle)
b@148 53 legendnames.append(subject_id)
b@148 54 plt.legend(linehandles, legendnames,
b@148 55 loc='upper right',
b@148 56 bbox_to_anchor=(1.1, 1), borderaxespad=0.)
b@148 57
b@148 58
b@148 59 plt.xlabel('Fragment')
b@148 60 plt.title('Box plot '+page_name)
b@148 61 plt.xlim(0, len(headerrow)+1) # only show relevant region, leave space left & right)
b@148 62 plt.xticks(range(1, len(headerrow)+1), headerrow) # show fragment names
b@148 63
b@148 64 plt.ylabel('Rating')
b@148 65 plt.ylim(0,1)
b@148 66
b@148 67 plt.show()
b@148 68 #exit()
b@148 69
nicholas@150 70 #TODO Save output automatically
nicholas@150 71