This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiurnal_Plot.py
52 lines (42 loc) · 1.45 KB
/
Diurnal_Plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import datetime as dt
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
"""
Diurnal_Plot.py:
Produce diurnal plots of fitbit data (5 min intervals).
Inspired by Stephen Wolfram's "The Personal Analytics of my Life"
(http://blog.stephenwolfram.com/2012/03/the-personal-analytics-of-my-life/)
Call with fitbit data as first argument.
"""
if __name__=='__main__':
filename = sys.argv[1]
minutes_in_day = (24 * 60)
X = []
Y = []
values = []
with open(filename,'r') as f:
day_num = -1
day = None
time_num = 0
for l in f:
parts = l.split(",")
date_s = parts[0]
value = int(parts[1])
datet = dt.datetime.strptime(date_s, "%Y-%m-%d %H:%M")
if day != datet.date():
day_num = day_num + 1
day = datet.date()
if value > 0:
values.append(value)
X.append(datet.date())
Y.append(minutes_in_day - (datet.time().hour * 60 + datet.time().minute))
#Y axis locations
locations = np.arange(0,24)*60
#Y axis labels
labels = ["%d:00" % ((24*60 - x) /60) for x in locations]
ax = plt.scatter(X,Y, c=values, s=3, facecolor='0.5', lw = 0, cmap=mpl.cm.YlGnBu)
plt.ylim([0,minutes_in_day])
plt.yticks(locations,labels)
plt.savefig("FitbitData.png", fmt="png");