# HG changeset patch # User Nicolas Saunier # Date 1360622137 18000 # Node ID f6f423e25c7f0d99d40fb0afb9de279d8a30402f # Parent 586ead03fc0080ea07f5089d191188366d79fd9c adding function to generate step plots (for cumulative number of vehicles) diff -r 586ead03fc00 -r f6f423e25c7f python/tests/utils.txt --- a/python/tests/utils.txt Mon Feb 11 16:01:15 2013 -0500 +++ b/python/tests/utils.txt Mon Feb 11 17:35:37 2013 -0500 @@ -41,6 +41,9 @@ >>> values[-1] 6.0 +>>> stepPlot([3, 5, 7, 8], 1, 10, 0) +([1, 3, 3, 5, 5, 7, 7, 8, 8, 10], [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]) + >>> LCSS(range(5), range(5), 0.1, lambda x,y:abs(x-y)) 5 >>> LCSS(range(1,5), range(5), 0.1, lambda x,y:abs(x-y)) diff -r 586ead03fc00 -r f6f423e25c7f python/utils.py --- 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