-
Notifications
You must be signed in to change notification settings - Fork 19
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
added plot_map #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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") | ||||||||||||||||||||||||||||
Comment on lines
+12
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include
Suggested change
|
||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||
Comment on lines
+22
to
24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: alphabetical order helps as number of imports grows:
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -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}") | ||||||||||||||||||||||||||||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're also re-using Some options:
I think the third, as there may be more visualisations added soon, and it will be useful to be able to have different names for different runs (for example, I might generate output for each year of activities, or summer vs. winter). |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||||||||||||||
main() |
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"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaults are |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove full stop to match the facets alt text.