diff --git a/README.md b/README.md index 5695cc7..f93a682 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ A plot of activity elevation profiles as small multiples. ![map](https://github.com/marcusvolz/strava_py/blob/main/plots/elevations001.png "A plot of activity elevation profiles as small multiples") +### Landscape + +Elevation profiles superimposed. + +![map](https://github.com/marcusvolz/strava_py/blob/main/plots/landscape001.png "Elevation profiles superimposed") + ## How to use ### Bulk export from Strava @@ -63,3 +69,9 @@ plot_map(df, lon_min=None, lon_max= None, lat_min=None, lat_max=None, ```python plot_elevations(df, output_file = 'elevations.png') ``` + +### Plot landscape + +```python +plot_landscape(df, output_file = 'landscape.png') +``` \ No newline at end of file diff --git a/plots/landscape001.png b/plots/landscape001.png new file mode 100644 index 0000000..79ba11b Binary files /dev/null and b/plots/landscape001.png differ diff --git a/src/stravavis/cli.py b/src/stravavis/cli.py index 222bad1..bd99cbd 100644 --- a/src/stravavis/cli.py +++ b/src/stravavis/cli.py @@ -28,6 +28,7 @@ def main(): # Normally imports go at the top, but scientific libraries can be slow to import # so let's validate arguments first + from stravavis.plot_landscape import plot_landscape from stravavis.plot_elevations import plot_elevations from stravavis.plot_facets import plot_facets from stravavis.plot_map import plot_map @@ -51,6 +52,11 @@ def main(): plot_elevations(df, output_file=outfile) print(f"Saved to {outfile}") + print("Plotting landscape...") + outfile = f"{args.output_prefix}-landscape.png" + plot_landscape(df, output_file=outfile) + print(f"Saved to {outfile}") + if __name__ == "__main__": main() diff --git a/src/stravavis/plot_landscape.py b/src/stravavis/plot_landscape.py new file mode 100644 index 0000000..6de6d5e --- /dev/null +++ b/src/stravavis/plot_landscape.py @@ -0,0 +1,37 @@ +import matplotlib.pyplot as plt +import pandas as pd + +def plot_landscape(df, output_file = 'landscape.png'): + + # Create a new figure + plt.figure() + + # Convert ele to numeric + df['ele'] = pd.to_numeric(df['ele']) + + # 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]] + 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) + + # Update plot aesthetics + plt.axis('off') + plt.margins(0) + plt.subplots_adjust(left = 0.05, right = 0.95, bottom = 0.05, top = 0.95) + plt.savefig(output_file, dpi = 600)