It is just about possible that some other seeker might want to plot weight graphs with little coloured regions.
I can’t face working out how to do syntax highlighting in substack, but I have round-tripped it, so if it doesn’t work on your machine that’s probably your fault:
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import datetime
import numpy as np
import pandas as pd
# Just cut and paste spreadsheet data here, it will deal with missing values
data_copied_from_fatods = """
08/08/23 94.2
07/08/23 95.3
06/08/23 95.8
05/08/23 95.1
04/08/23 95.9
03/08/23 95.5
02/08/23 94.9
01/08/23 94.3
31/07/23 94.2
30/07/23 95.1
29/07/23 94
28/07/23 95.5
27/07/23 95.3
26/07/23
25/07/23 95.1
24/07/23
23/07/23 94.9
22/07/23 94.6
21/07/23 95
20/07/23 95.5
19/07/23 95.6
18/07/23 94.8
17/07/23 95.9
16/07/23 95.5
15/07/23 94.9
14/07/23 95.3
13/07/23 96.2
12/07/23 95.1
11/07/23 96.4
10/07/23 96.1
09/07/23 96.8
08/07/23 96.3
07/07/23 96.8
06/07/23 95.4
05/07/23 95.6
04/07/23 96
03/07/23 95.4
02/07/23 95.3
01/07/23 94.9
30/06/23 95.6
29/06/23 94.6
28/06/23 94.2
27/06/23 95.1
26/06/23 95.1
25/06/23 94.4
24/06/23 96.2
23/06/23 96.2
22/06/23 96.2
21/06/23 97
20/06/23 96.8
19/06/23 97
18/06/23 97.3
17/06/23 97.5
16/06/23 97.7
15/06/23 97.6
14/06/23 97.8
13/06/23 98
12/06/23 98
11/06/23 98.5
10/06/23 97.6
09/06/23 97.6
08/06/23 97.3
07/06/23 96.8
06/06/23 97.1
05/06/23 97
04/06/23 98.2
03/06/23 98.2
02/06/23 97.5
01/06/23 97.4
31/05/23 97.7
30/05/23 98.3
29/05/23 99
28/05/23 99.6
27/05/23 98.8
26/05/23 98.5
25/05/23 98.8
24/05/23 98.6
23/05/23 98.6
22/05/23 100.3
21/05/23 99
20/05/23 99.4
19/05/23 98.8
18/05/23 98.3
17/05/23 98.6
16/05/23 99.2
15/05/23
14/05/23
13/05/23
12/05/23
11/05/23
10/05/23
09/05/23
08/05/23
07/05/23
06/05/23
05/05/23
04/05/23
03/05/23
02/05/23
01/05/23
30/04/23
29/04/23
28/04/23
27/04/23
26/04/23
25/04/23
24/04/23
23/04/23
22/04/23
21/04/23 98.7
20/04/23 98.4
19/04/23 98.1
18/04/23 97.6
17/04/23 99.1
16/04/23 98.1
15/04/23 98.4
14/04/23 98.4
13/04/23 98.5
12/04/23 99.2
"""
#some made-up numbers from the past
#93 kilos on Christ's Boathouse scales at beginning and end of pandemic (+0.75 cos those scales don't agree with mine)
#97 kilos on same scales last December, prompting weight worries
#rowing weight of 85 kilos, lifetime stable as far as I know back to when I was 25 (1995)
# I also remember 13 1/2 stone, BMI~27 as being 'my weight'. That's ~85 kilos
#student weight of 10 1/2 stone, as measured by KCBC, pre growth period so probably 1989?
historical_data="""
01/12/22 97.75
01/04/21 93.75
01/04/20 93.75
01/01/10 85.0
01/01/95 85.0
01/01/89 66.67
18/07/70 4
18/10/69 0
"""
data=data_copied_from_fatods+historical_data
# throw away everything that is not a pair
d = [l.split() for l in data.splitlines() if len(l.split()) == 2]
#print(d)
d2 = [(datetime.datetime.strptime(date, "%d/%m/%y"), float(w)) for (date, w) in d]
#print(d2)
df = pd.DataFrame(
{
"date": np.array([a for (a, b) in d2]),
"weight": [b for (a, b) in d2],
}
)
plt.plot(df.date, df.weight, label="weight", linewidth=3)
# add title and axis labels
plt.title("The Heart Attack Diet")
#plt.xlabel("Date")
#plt.ylabel("Weight")
# add legend
# plt.legend()
# a grey horizontal region
#plt.axhspan(97, 98, facecolor="0.2", alpha=0.5)
# a blue vertical bar for visiting Mum
plt.axvspan(
datetime.datetime.strptime("22/04/23", "%d/%m/%y"),
datetime.datetime.strptime("15/05/23", "%d/%m/%y"),
facecolor="r",
alpha=0.5,
)
# a blue vertical bar for ex150ish-1
plt.axvspan(
datetime.datetime.strptime("28/05/23", "%d/%m/%y"),
datetime.datetime.strptime("07/06/23", "%d/%m/%y"),
facecolor="b",
alpha=0.5,
)
# a blue vertical bar for ex150ish-2
plt.axvspan(
datetime.datetime.strptime("17/06/23", "%d/%m/%y"),
datetime.datetime.strptime("01/07/23", "%d/%m/%y"),
facecolor="b",
alpha=0.5,
)
# display plot
plt.show()