2D Histogram

GPS Location Heatmap

Urban check-in density with hotspot clusters

Output
GPS Location Heatmap
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

# GPS tracking data simulation
np.random.seed(42)
n_points = 15000

# City center with multiple hotspots
lat_base, lon_base = 40.7128, -74.0060

# Multiple activity centers
centers = [(0, 0), (0.02, 0.01), (-0.01, 0.02), (0.015, -0.015)]
lat, lon = [], []
for cx, cy in centers:
    n = n_points // len(centers)
    lat.extend(np.random.normal(lat_base + cx, 0.008, n))
    lon.extend(np.random.normal(lon_base + cy, 0.008, n))

lat, lon = np.array(lat), np.array(lon)

# Map dark theme
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(10, 8))
fig.patch.set_facecolor('#0a0f14')
ax.set_facecolor('#0a0f14')

# Custom colormap - heat signature
colors = ['#0a0f14', '#0a1a28', '#1a3040', '#2a4a58', '#3a6a70', 
          '#5a9a88', '#7acaa0', '#a0eab8', '#c0ffd0', '#e0ffe8', '#ffffff']
cmap = LinearSegmentedColormap.from_list('gps_heat', colors, N=256)

# 2D histogram
h = ax.hist2d(lon, lat, bins=60, cmap=cmap, cmin=1)

# Styled colorbar
cbar = plt.colorbar(h[3], ax=ax, pad=0.02, shrink=0.85)
cbar.ax.set_facecolor('#0a0f14')
cbar.set_label('Location Pings', fontsize=11, color='#a0e0c0', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#a0e0c0')
cbar.outline.set_edgecolor('#2a4a40')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#a0e0c0', fontsize=9)

# Labels
ax.set_xlabel('Longitude', fontsize=13, color='#a0e0c0', fontweight='600', labelpad=10)
ax.set_ylabel('Latitude', fontsize=13, color='#a0e0c0', fontweight='600', labelpad=10)
ax.set_title('GPS Activity Heatmap', fontsize=16, color='white', fontweight='bold', pad=20)

ax.tick_params(colors='#80c0a0', labelsize=10, length=0)
for spine in ax.spines.values():
    spine.set_visible(False)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support