Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
296:586ead03fc00 | 297:f6f423e25c7f |
---|---|
243 | 243 |
244 ######################### | 244 ######################### |
245 # plotting section | 245 # plotting section |
246 ######################### | 246 ######################### |
247 | 247 |
248 def stepPlot(X, firstX, lastX, initialCount = 0): | |
249 '''for each value in x, increment by one the initial count | |
250 returns the lists that can be plotted | |
251 to obtain a step plot increasing by one for each value in x, from first to last value''' | |
252 | |
253 sortedX = [] | |
254 counts = [initialCount] | |
255 for x in sorted(X): | |
256 sortedX += [x,x] | |
257 counts.append(counts[-1]) | |
258 counts.append(counts[-1]+1) | |
259 counts.append(counts[-1]) | |
260 return [firstX]+sortedX+[lastX], counts | |
261 | |
248 class PlottingPropertyValues: | 262 class PlottingPropertyValues: |
249 def __init__(self, values): | 263 def __init__(self, values): |
250 self.values = values | 264 self.values = values |
251 | 265 |
252 def __getitem__(self, i): | 266 def __getitem__(self, i): |