-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpace-visualization.py
More file actions
62 lines (49 loc) · 1.77 KB
/
Copy pathpace-visualization.py
File metadata and controls
62 lines (49 loc) · 1.77 KB
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
53
54
55
56
57
58
59
60
61
62
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
from matplotlib.axes import Axes
from matplotlib import figure
def pace_formatter(x, pos=None):
mins = int(x // 60)
secs = int(x % 60)
return f"{mins}:{secs:02d}"
def plot(ax: Axes, df: pd.DataFrame, title: str):
ax.plot(
df["Date"],
df["Avg Pace"],
marker="o",
linestyle="-",
color="b",
)
ax.set_title(title)
ax.set_xlabel("Date")
ax.set_ylabel("Pace (min:sec)")
ax.xaxis.set_tick_params(rotation=45)
ax.grid(True)
ax.yaxis.set_major_formatter(FuncFormatter(pace_formatter))
for hr_zone in range(0, 6):
with open(f"./zone-{hr_zone}-runs.csv") as hr_zone_runs_csv:
hr_zone_runs = pd.read_csv(hr_zone_runs_csv)
if hr_zone_runs.size < 2:
continue
hr_zone_runs["Date"] = pd.to_datetime(hr_zone_runs["Date"])
hr_zone_runs["Avg Pace"] = pd.to_timedelta(
"00:" + hr_zone_runs["Avg Pace"]
).dt.total_seconds()
df_less_than_5_miles = hr_zone_runs[(hr_zone_runs["Distance"] < 5)]
df_5_to_10_miles = hr_zone_runs[
(hr_zone_runs["Distance"] >= 5) & (hr_zone_runs["Distance"] <= 10)
]
df_greater_than_10_miles = hr_zone_runs[hr_zone_runs["Distance"] > 10]
plt.rc("font", size=8)
fig: figure
ax1: Axes
ax2: Axes
ax3: Axes
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(12, 6))
plot(ax1, df_less_than_5_miles, f"< 5 Mile Runs - Zone {hr_zone}")
plot(ax2, df_5_to_10_miles, f"5-10 Mile Runs - Zone {hr_zone}")
plot(ax3, df_greater_than_10_miles, f"10+ Mile Runs - Zone {hr_zone}")
# Adjust layout
plt.tight_layout()
plt.show()