b@148: import sys b@148: import os b@148: import csv b@148: import matplotlib.pyplot as plt b@148: b@148: rating_folder = 'ratings/' # folder with rating csv files b@148: b@148: colormap = ['b', 'r', 'g', 'c', 'm', 'y', 'k'] # colormap for to cycle through b@148: markerlist = ["x", ".", "o", "*", "+", "v", ">", "<", "8", "s", "p"] b@148: b@148: # get every csv file in folder b@148: for file in os.listdir(rating_folder): # You have to put this in folder where rating csv files are. b@148: if file.endswith(".csv"): b@148: page_name = file[:-4] # file name (without extension) is page ID b@148: b@148: with open(rating_folder+file, 'r') as readfile: # read this csv file b@148: filereader = csv.reader(readfile, delimiter=',') b@148: headerrow = filereader.next() # use headerrow as X-axis b@148: headerrow = headerrow[1:] b@148: b@148: b@148: increment = 0 b@148: linehandles = [] b@148: legendnames = [] b@148: for row in filereader: b@148: subject_id = row[0][:-4] b@148: plothandle, = plt.plot(range(1,len(row)), # x-values b@148: row[1:], # y-values: csv values except subject name b@148: color=colormap[increment%len(colormap)], b@148: marker=markerlist[increment%len(markerlist)], b@148: markersize=10, b@148: linestyle='None', b@148: label=subject_id b@148: ) b@148: increment += 1 # increase counter b@148: linehandles.append(plothandle) b@148: legendnames.append(subject_id) b@148: b@148: b@148: plt.xlabel('Fragment') b@148: plt.title('Individual ratings '+page_name) b@148: plt.xlim(0, len(headerrow)+1) # only show relevant region, leave space left & right) b@148: plt.xticks(range(1, len(headerrow)+1), headerrow) # show fragment names b@148: b@148: plt.ylabel('Rating') b@148: plt.ylim(0,1) b@148: b@148: plt.legend(linehandles, legendnames, b@148: loc='upper right', b@148: bbox_to_anchor=(1.1, 1), borderaxespad=0.) b@148: b@148: #TODO Put legend outside of box b@148: #TODO Why two markers in legend? b@148: b@148: plt.show() b@148: #exit() b@148: nicholas@150: #TODO Save output automatically nicholas@150: