I have a list of dates that happen throughout 2013. I wish to construct a graph showing a cumulative total of elements that happen before that date.
I have a working algorithm, but it seems too slow and inefficient.
Let's generate some random dates:
dates = {2013, #[[1]], #[[2]]} & /@ Transpose@{RandomInteger[{1, 12}, {100}],
RandomInteger[{1, 30}, {100}]};
Define a function that calculates the totals:
datecounts[dates_, effectivedate_, spanindays_] := Module[{range, compares},
range = DateRange[effectivedate, DatePlus[effectivedate, spanindays]];
compares = Partition[(AbsoluteTime[#[[1]]] > AbsoluteTime[#[[2]]]) & /@
Tuples[{range, dates}], Length[dates]];
Transpose@{range, Count[#, True] & /@ compares}]
And graph the results:
DateListPlot[datecounts[dates, {2013, 1, 1}, 365], PlotStyle -> {Thickness[0.003]},
Joined -> True, GridLines -> Automatic, FrameLabel -> {Null, "Total Count"}]
Any help in improving efficiency or better use of functions is greatly appreciated.






InterpolationOrder -> 0to get your nice flat lines. – Verbeia Feb 01 '13 at 04:55