Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More progress bars for slow loops, and refactor #15

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/stravavis/plot_landscape.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import matplotlib.pyplot as plt
import pandas as pd
from rich.progress import track


def plot_landscape(df, output_file = 'landscape.png'):

Expand All @@ -11,25 +13,24 @@ def plot_landscape(df, output_file = 'landscape.png'):

# Create a list of activity names
activities = df['name'].unique()
n = len(activities)


# Normalize dist
processed = []
for i in range(n):
df_i = df[df['name'] == activities[i]]

for activity in track(activities, "Processing tracks"):
df_i = df[df['name'] == activity]
df_i["dist_norm"] = (df_i["dist"] - df_i["dist"].min()) / (df_i["dist"].max() - df_i["dist"].min())
processed.append(df_i)

df = pd.concat(processed)

# Plot activities one by one
for i in range(n):
X = df[df['name'] == activities[i]]['dist_norm']
Y = df[df['name'] == activities[i]]['ele']
plt.fill_between(X, Y, color = 'black', alpha = 0.03, linewidth = 0)
plt.plot(X, Y, color = 'black', alpha = 0.125, linewidth = 0.25)
for activity in track(activities, "Plotting activities"):
x = df[df['name'] == activity]['dist_norm']
y = df[df['name'] == activity]['ele']
plt.fill_between(x, y, color='black', alpha=0.03, linewidth=0)
plt.plot(x, y, color='black', alpha=0.125, linewidth=0.25)

# Update plot aesthetics
plt.axis('off')
plt.margins(0)
Expand Down
11 changes: 6 additions & 5 deletions src/stravavis/plot_map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import matplotlib.pyplot as plt
from rich.progress import track


def plot_map(df, lon_min=None, lon_max= None, lat_min=None, lat_max=None,
alpha=0.3, linewidth=0.3, output_file="map.png"):
Expand All @@ -21,13 +23,12 @@ def plot_map(df, lon_min=None, lon_max= None, lat_min=None, lat_max=None,

# Create a list of activity names
activities = df['name'].unique()
n = len(activities)

# Plot activities one by one
for i in range(n):
X = df[df['name'] == activities[i]]['lon']
Y = df[df['name'] == activities[i]]['lat']
plt.plot(X, Y, color = 'black', alpha = alpha, linewidth = linewidth)
for activity in track(activities, "Plotting activities"):
x = df[df['name'] == activity]['lon']
y = df[df['name'] == activity]['lat']
plt.plot(x, y, color='black', alpha=alpha, linewidth=linewidth)

# Update plot aesthetics
plt.axis('off')
Expand Down