In [1]:
%matplotlib inline
In [2]:
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
initial_mass = 75.5
target_mass = 65.5
start_date = datetime(2014, 1, 1)
end_date = datetime(2014, 8, 1)
total_days = (end_date - start_date).days
x = np.linspace(0, total_days, total_days)
y = initial_mass * np.ones(total_days)
f = open('/Users/alexey/Projects/weights.dat', 'r')
day = 0
weights = -1*np.ones(total_days)
for l in f:
vals = l.split()
if len(vals) > 1:
weights[day] = vals[1]
day += 1
f.close()
plt.figure(figsize=(12, 12))
with plt.xkcd():
plt.plot(x, y, label='No loss')
slim_coeff = 1 - 0.99 ** (1.0/7.0)
y1 = initial_mass * np.exp(np.log(1 - slim_coeff) * x)
plt.plot(x, y1, label='1% per week loss')
y2 = target_mass * np.ones(total_days)
plt.plot(x, y2, label='Target weight')
plt.xlim([0, total_days])
plt.ylim([55, 80])
plt.minorticks_on()
plt.xlabel('Days from the start of the expreiment')
plt.ylabel('Weight, kg')
plt.plot(x, weights, 'ko', mew=2, mec='black', label='Measured weight')
plt.legend()
plt.savefig('/Users/alexey/Projects/weights.png')
In [4]:
In [ ]: