Ridgeline Plot

Intensity Ridgeline

Ridgeline with color gradient by intensity.

Output
Intensity Ridgeline
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {'low': '#C7D2FE', 'high': '#4F46E5', 'background': '#FFFFFF', 'text': '#1E293B'}

np.random.seed(42)
x = np.linspace(0, 10, 150)
categories = ['Week 1', 'Week 2', 'Week 3', 'Week 4', 'Week 5']

fig, ax = plt.subplots(figsize=(10, 7), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

for i, cat in enumerate(categories):
    intensity = (i + 1) / len(categories)
    y = (1 + 0.2*i) * (np.sin(x + i*0.5) + 0.5*np.sin(2*x) + 1.2) + np.random.normal(0, 0.05, len(x))
    baseline = i * 1.5
    
    r1, g1, b1 = int(COLORS['low'][1:3], 16)/255, int(COLORS['low'][3:5], 16)/255, int(COLORS['low'][5:7], 16)/255
    r2, g2, b2 = int(COLORS['high'][1:3], 16)/255, int(COLORS['high'][3:5], 16)/255, int(COLORS['high'][5:7], 16)/255
    color = (r1 + intensity*(r2-r1), g1 + intensity*(g2-g1), b1 + intensity*(b2-b1))
    
    ax.fill_between(x, baseline, baseline + y * 0.8, color=color, alpha=0.85, zorder=5-i)
    ax.text(-0.3, baseline + 0.8, cat, fontsize=9, fontweight='bold', color=COLORS['text'], ha='right', va='center')

ax.set_xlim(-2, 10)
ax.set_ylim(-0.5, 10)
ax.axis('off')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support