Skip to content

Commit

Permalink
Merge pull request #15 from hugovk/more-progress-bars
Browse files Browse the repository at this point in the history
More progress bars for slow loops, and refactor
  • Loading branch information
marcusvolz authored Feb 14, 2022
2 parents 3456c32 + a9060fb commit 0082e88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
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

0 comments on commit 0082e88

Please sign in to comment.