# HG changeset patch # User Brecht De Man # Date 1476693231 -7200 # Node ID 4903cda56c2a190e9135a02c350ba8e31d58302a # Parent 096bdb64d116cd9080e048e561d2247c47ecc14b Timelines (Python): Y label and ticks as on interface E.g. if the scale is called 'Spatial quality', this will be the Y label, and if ticks are 'Poor / Okay / Great' at 25%/50%/70%', these will be the Y ticks. diff -r 096bdb64d116 -r 4903cda56c2a python/timeline_view_movement.py --- a/python/timeline_view_movement.py Mon Sep 19 21:02:36 2016 +0200 +++ b/python/timeline_view_movement.py Mon Oct 17 10:33:51 2016 +0200 @@ -290,12 +290,35 @@ plt.ylabel('Rating') # default plt.ylim(0, 1) # rating between 0 and 1 - # TO DO: - # Y axis title and tick labels as specified in 'setup' for corresponding page + # Y axis title and tick labels as specified in 'setup' + # for corresponding page + page_setup = root.find("./waet/page[@id='"+page_name+"']") + # 'ref' of page is 'id' in page setup + # Different plots for different axes + interfaces = page_setup.findall("./interface") + interface_title = interfaces[0].find("./title") + scales = interfaces[0].findall("./scales") # get first interface by default + scalelabels = scales[0].findall("./scalelabel") # get first scale by default + + labelpos = [] # array of scalelabel positions + labelstr = [] # array of strings at labels + for scalelabel in scalelabels: + labelpos.append(float(scalelabel.get('position'))/100.0) + labelstr.append(scalelabel.text) + + # use interface name as Y axis label + if interface_title is not None: + plt.ylabel(interface_title.text) + else: + plt.ylabel('Rating') # default + + if len(labelpos): + plt.yticks(labelpos, labelstr) #plt.show() # uncomment to show plot; comment when just saving #exit() + # save as PDF plt.savefig(timeline_folder+subject_id+"-"+page_name+".pdf", bbox_inches='tight') plt.close()