Skip to content

Commit

Permalink
Merge pull request #2 from marcusvolz/development
Browse files Browse the repository at this point in the history
added plot_map
  • Loading branch information
marcusvolz authored Feb 6, 2022
2 parents 1de8b22 + 8357025 commit e968fbc
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ A plot of activities as small multiples. The concept behind this plot was origin

![facets](https://github.com/marcusvolz/strava_py/blob/main/plots/facets001.png "Facets, showing activity outlines")

### Map

A map of activities viewed in plan.

![map](https://github.com/marcusvolz/strava_py/blob/main/plots/map001.png "A map of activities viewed in plan.")

## How to use

### Bulk export from Strava
Expand Down Expand Up @@ -38,3 +44,10 @@ df = process_data(<path to folder with GPX and / or FIT files>)
```python
plot_facets(df, output_file = 'plot.png')
```

### Plot activity map

```python
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")
```
Binary file added plots/map001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/strava_py/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ def main():
parser.add_argument(
"-o", "--output_file", default="plot.png", help="Output PNG file"
)
parser.add_argument("lon_min", default=None, help="Minimum longitude for plot_map (values less than this are removed from the data)")
parser.add_argument("lon_max", default=None, help="Maximum longitude for plot_map (values greater than this are removed from the data)")
parser.add_argument("lat_min", default=None, help="Minimum latitude for plot_map (values less than this are removed from the data)")
parser.add_argument("lat_max", default=None, help="Maximum latitude for plot_map (values greater than this are removed from the data)")
parser.add_argument("alpha", default=0.4, help="Line transparency. 0 = Fully transparent, 1 = No transparency")
parser.add_argument("linewidth", default=0.4, help="Line width")
args = parser.parse_args()

# Normally imports go at the top, but scientific libraries can be slow to import
# so let's validate arguments first
from strava_py.plot_map import plot_map
from strava_py.plot_facets import plot_facets
from strava_py.process_data import process_data

Expand All @@ -23,6 +30,10 @@ def main():
plot_facets(df, output_file=args.output_file)
print(f"Saved to {args.output_file}")

print("Plotting map...")
plot_facets(df, output_file=args.output_file)
print(f"Saved to {args.output_file}")


if __name__ == "__main__":
main()
34 changes: 34 additions & 0 deletions src/strava_py/plot_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import matplotlib.pyplot as plt

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"):

# Remove data outside the input ranges for lon / lat
if lon_min is not None:
df = df[df['lon'] >= lon_min]

if lon_max is not None:
df = df[df['lon'] <= lon_max]

if lat_min is not None:
df = df[df['lat'] >= lat_min]

if lat_max is not None:
df = df[df['lat'] <= lat_max]

# 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)

# Update plot aesthetics
plt.axis('off')
plt.axis('equal')
plt.margins(0)
plt.subplots_adjust(left = 0.05, right = 0.95, bottom = 0.05, top = 0.95)
plt.savefig(output_file, dpi = 600)

0 comments on commit e968fbc

Please sign in to comment.