annotate scripts/score_boxplot.py @ 1601:1c7cd4613a96

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