diff python/utils.py @ 297:f6f423e25c7f

adding function to generate step plots (for cumulative number of vehicles)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 11 Feb 2013 17:35:37 -0500
parents fa95796a76b3
children 27f06d28036d
line wrap: on
line diff
--- a/python/utils.py	Mon Feb 11 16:01:15 2013 -0500
+++ b/python/utils.py	Mon Feb 11 17:35:37 2013 -0500
@@ -245,6 +245,20 @@
 # plotting section
 #########################
 
+def stepPlot(X, firstX, lastX, initialCount = 0):
+    '''for each value in x, increment by one the initial count
+    returns the lists that can be plotted 
+    to obtain a step plot increasing by one for each value in x, from first to last value'''
+    
+    sortedX = []
+    counts = [initialCount]
+    for x in sorted(X):
+        sortedX += [x,x]
+        counts.append(counts[-1])
+        counts.append(counts[-1]+1)
+    counts.append(counts[-1])
+    return [firstX]+sortedX+[lastX], counts
+
 class PlottingPropertyValues:
     def __init__(self, values):
         self.values = values