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

Fix squashed maps #21

Merged
merged 1 commit into from
Sep 4, 2022
Merged
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: 27 additions & 0 deletions src/stravavis/plot_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
from math import log, pi, tan

import matplotlib.pyplot as plt
from rich.progress import track

# Dummy units
MAP_WIDTH = 1
MAP_HEIGHT = 1


def convert_x(lon):
# Get x value
x = (lon + 180) * (MAP_WIDTH / 360)
return x


def convert_y(lat):
# Convert from degrees to radians
lat_rad = lat * pi / 180

# Get y value
mercator_n = log(tan((pi / 4) + (lat_rad / 2)))
y = (MAP_HEIGHT / 2) + (MAP_WIDTH * mercator_n / (2 * pi))
return y


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 Down Expand Up @@ -28,6 +50,11 @@ def plot_map(df, lon_min=None, lon_max= None, lat_min=None, lat_max=None,
for activity in track(activities, "Plotting activities"):
x = df[df['name'] == activity]['lon']
y = df[df['name'] == activity]['lat']

# Transform to Mercator projection so maps aren't squashed away from equator
x = x.transform(convert_x)
y = y.transform(convert_y)

plt.plot(x, y, color='black', alpha=alpha, linewidth=linewidth)

# Update plot aesthetics
Expand Down