changeset 2568:4903cda56c2a

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.
author Brecht De Man <b.deman@qmul.ac.uk>
date Mon, 17 Oct 2016 10:33:51 +0200
parents 096bdb64d116
children c8e6991951ad
files python/timeline_view_movement.py
diffstat 1 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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()