From f5d5e0227520864a1c951ecdd3c6dceca8fae1fb Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Mon, 27 Aug 2018 13:17:53 -0700 Subject: [PATCH] factor out some common code; ensure x and y axes pair exactly --- appfigures.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/appfigures.py b/appfigures.py index 864864c..d844293 100755 --- a/appfigures.py +++ b/appfigures.py @@ -37,12 +37,16 @@ def combineDailyToWeekly(pj, func): return [func(pj[i : i + chunkSize]) for i in range(0, len(pj), chunkSize)] +def getLastElem(arr): + return arr[-1] + + def getDownloadsWeekly(t): - return combineDailyToWeekly(t[0], lambda _: _[-1]), combineDailyToWeekly(t[1], sum) + return combineDailyToWeekly(t[0], getLastElem), combineDailyToWeekly(t[1], sum) def getUpdatesWeekly(t): - return combineDailyToWeekly(t[0], lambda _: _[-1]), combineDailyToWeekly(t[2], sum) + return combineDailyToWeekly(t[0], getLastElem), combineDailyToWeekly(t[2], sum) def getDownloadsDaily(t): @@ -61,6 +65,8 @@ def plotData(filename, ylabel, timespan, x, y): import matplotlib.pyplot as plt import matplotlib.dates as mdates + assert len(x) == len(y) + plt.clf() plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m-%d")) plt.gca().xaxis.set_major_locator(mdates.AutoDateLocator())