-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.py
42 lines (33 loc) · 1.57 KB
/
example.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
from withings import *
import matplotlib.pyplot as plt #for plotting weights
from datetime import datetime
from pandas import *
#-----------------------------------
#get your consumer key and secret after registering
#as a developer here: https://oauth.withings.com/en/partner/add
consumer_key='your_consumer_key_here_1111111111111111111111111111111111111111'
consumer_secret='your_consumer_secret_here_1111111111111111111111111111111111111111111'
#the first argument here is the email address you used to register
#for a Withings developer account
wobj=Withings('[email protected]',consumer_key,consumer_secret)
(dates,weights)=wobj.get_weights()
print "You have ",len(weights)," weight measurements recorded"
#pandas allows us to build a timeseries object which will display
#dates along the x-axis when plotted and can have rolling window
#functions applied to it, like rolling_mean,rolling_median,rolling_std,etc.
rdates=[datetime.fromtimestamp(i) for i in dates]
ts=Series(weights,index=rdates)
#the marker='o' option will put a dot at each measurement point
#which, if you mouse-over will display the value
ts.plot(marker='o',color='b')
plt.ylabel('Weight(lbs)')
#this will overlay a smoothed curve which suggests the trend
#of the underlying data
rolling_mean(ts,len(weights)/float(7)).plot(color='r',linewidth='3')
plt.show()
#if you don't have pandas, or have problems installing it,
#the code below makes a basic plot without the nice date labels
#on the x-axis
#plt.plot(dates,weights,'-o')#super simple plotting on one axis
#plt.ylabel('Weight(lbs)')
#plt.show()