Skip to content

Instantly share code, notes, and snippets.

@stephenc
Created July 28, 2025 21:01
Show Gist options
  • Save stephenc/30c5ec8cb00ed84cf95397fcece2a90c to your computer and use it in GitHub Desktop.
Save stephenc/30c5ec8cb00ed84cf95397fcece2a90c to your computer and use it in GitHub Desktop.
Finger Saver Lesson 6
import pandas as pd
df = pd.read_csv('myGPSData.csv')
df.head()
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
import contextily as ctx
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(10,10))
gdf_web_mercator.plot(
ax=ax,
marker='o',
color='orange',
edgecolor='black',
markersize=20,
alpha=0.7,
label='GPS Points',
)
ctx.add_basemap(ax, source=ctx.providers.CartoDB.Positron)
ax.set_title(
"Customized Geospatial Plot",
fontsize=16,
color='navy'
)
ax.set_axis_off()
plt.legend()
plt.show()
fig, ax = plt.subplots(figsize=(12,10))
gdf_web_mercator.plot(
ax=ax,
marker='x',
color='red',
markersize=100,
alpha=0.5,
label='GPS Points',
)
ctx.add_basemap(ax, source=ctx.providers.CartoDB.Positron)
ax.set_title("GPS Plot", fontsize=16)
ax.set_xlabel("Longitude", fontsize=12)
ax.set_ylabel("Latitude", fontsize=12)
plt.legend()
plt.show()
unique_hours = sorted(gdf['hour'].unique())
num_cols = 4
num_rows = (len(unique_hours) + num_cols - 1) // num_cols
fig, axes = plt.subplots(num_rows, num_cols, figsize=(20, 4 * num_rows))
axes = axes.flatten()
for i, hour in enumerate(unique_hours):
ax = axes[i]
subset = gdf[gdf['hour'] == hour]
subset.plot(ax=ax, color='blue', marker='o', markersize=20, alpha=0.6)
ax.set_title(f"Hour: {hour}")
ax.set_axis_off()
for j in range(i+1, len(axes)):
axes[j].set_visible(False)
plt.tight_layout()
plt.suptitle("Time-Sliced GPS Views by Hour", fontsize=20, y=1.02)
plt.show()
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots(figsize=(5,4))
def update(frame):
ax.clear()
slices = gdf[gdf['minute'] == frame]
if not slices.empty:
slices.plot(ax=ax, color='blue', marker='o', markersize=30, alpha=0.6)
ax.set_title(f"Time: {frame}", fontsize=14)
ax.set_xlim(gdf.total_bounds[[0,2]])
ax.set_ylim(gdf.total_bounds[[1,3]])
ax.set_axis_off()
anim = FuncAnimation(fig, update, frames=minute_slices, repeat=False)
from IPython.display import HTML
html_output = anim.to_html5_video()
plt.close()
HTML(html_output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment