Horizon Chart

Blood Glucose Monitor Horizon

Continuous glucose monitoring horizon chart with pink gradient for elevated readings.

Output
Blood Glucose Monitor Horizon
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {
    'high': ['#FCE7F3', '#F9A8D4', '#EC4899'],
    'low': ['#DBEAFE', '#93C5FD', '#3B82F6'],
    'background': '#ffffff',
    'text': '#1f2937',
    'grid': '#e5e7eb',
}

np.random.seed(777)
hours = np.linspace(0, 24, 288)  # 5-min readings
# Glucose pattern with meal spikes
fasting = 90
breakfast = 40 * np.exp(-((hours - 8)**2) / 2)
lunch = 50 * np.exp(-((hours - 13)**2) / 2)
dinner = 45 * np.exp(-((hours - 19)**2) / 2)
glucose = fasting + breakfast + lunch + dinner + np.random.normal(0, 8, len(hours))
glucose_centered = glucose - 100  # Center at 100 mg/dL

fig, ax = plt.subplots(figsize=(14, 3), facecolor=COLORS['background'])
ax.set_facecolor(COLORS['background'])

band = 25

# High glucose
ax.fill_between(hours, 0, np.clip(glucose_centered, 0, band), color=COLORS['high'][0])
ax.fill_between(hours, 0, np.clip(glucose_centered - band, 0, band), color=COLORS['high'][1])
ax.fill_between(hours, 0, np.clip(glucose_centered - 2*band, 0, band), color=COLORS['high'][2])

# Low glucose
ax.fill_between(hours, 0, np.clip(glucose_centered, -band, 0), color=COLORS['low'][0])
ax.fill_between(hours, 0, np.clip(glucose_centered + band, -band, 0), color=COLORS['low'][1])
ax.fill_between(hours, 0, np.clip(glucose_centered + 2*band, -band, 0), color=COLORS['low'][2])

ax.axhline(0, color=COLORS['grid'], linewidth=1)
ax.set_xlim(0, 24)
ax.set_ylim(-30, 30)

ax.set_title('Continuous Glucose Monitor (mg/dL from baseline)', color=COLORS['text'], fontsize=12, fontweight='bold', pad=10)
ax.set_xlabel('Hour', color=COLORS['text'], fontsize=10)
ax.set_ylabel('Glucose', color=COLORS['text'], fontsize=10)
ax.set_xticks([0, 6, 12, 18, 24])

for spine in ax.spines.values():
    spine.set_color(COLORS['grid'])
ax.tick_params(colors=COLORS['text'], labelsize=9)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Time Series

Did this help you?

Support PyLucid to keep it free & growing

Support