Ridgeline Plot

Commute Time by City

Daily commute duration distributions across major cities

Output
Commute Time by City
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(42)
cities = ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'Seattle']
commute_means = [42, 55, 35, 32, 28, 30]
commute_stds = [18, 22, 14, 12, 10, 12]

fig, ax = plt.subplots(figsize=(12, 8), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

colors = ['#F5276C', '#F54927', '#F5B027', '#6CF527', '#27D3F5', '#4927F5']

x = np.linspace(0, 120, 200)
overlap = 2.2

for i, (city, mean, std, color) in enumerate(zip(cities, commute_means, commute_stds, colors)):
    data = np.random.gamma(mean/5, 5, 1000)
    kde = stats.gaussian_kde(data)
    y = kde(x) * 10
    y_offset = i * overlap
    
    ax.fill_between(x, y_offset, y + y_offset, alpha=0.85, color=color, edgecolor='white', linewidth=0.8)
    ax.text(-5, y_offset + 0.3, city, fontsize=10, color='white', va='center', ha='right', fontweight='500')

ax.set_xlim(-30, 120)
ax.set_ylim(-0.5, len(cities) * overlap + 2)
ax.set_xlabel('Commute Time (minutes)', color='white', fontsize=11, fontweight='500')
ax.set_title('Commute Time Distribution by City', color='white', fontsize=14, fontweight='bold', pad=20)
ax.tick_params(colors='#888888', labelsize=9)
ax.set_yticks([])
for spine in ax.spines.values():
    spine.set_visible(False)
ax.spines['bottom'].set_visible(True)
ax.spines['bottom'].set_color('#333333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support