Area Chart

Forecast Uncertainty

Prediction with expanding confidence cone.

Output
Forecast Uncertainty
Python
import matplotlib.pyplot as plt
import numpy as np

# Data - Forecast with expanding uncertainty
np.random.seed(42)
x_hist = np.arange(0, 10)
y_hist = 100 + 5 * x_hist + np.random.normal(0, 3, len(x_hist))

x_fore = np.arange(10, 16)
y_fore = 100 + 5 * x_fore
uncertainty = np.array([5, 10, 16, 23, 31, 40])

# Figure - DARK THEME
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

# Historical data
ax.plot(x_hist, y_hist, color='#27D3F5', linewidth=2.5, label='Historical')
ax.scatter(x_hist, y_hist, color='#27D3F5', s=50, zorder=5, edgecolors='white', linewidth=0.5)

# Forecast with uncertainty cone
ax.fill_between(x_fore, y_fore - uncertainty*2, y_fore + uncertainty*2, alpha=0.2, color='#F5276C', label='95% CI')
ax.fill_between(x_fore, y_fore - uncertainty, y_fore + uncertainty, alpha=0.3, color='#F5276C', label='68% CI')
ax.plot(x_fore, y_fore, color='#F5276C', linewidth=2.5, linestyle='--', label='Forecast')

# Vertical line at forecast start
ax.axvline(9.5, color='#F5B027', linewidth=1.5, linestyle=':', alpha=0.7)
ax.text(9.7, ax.get_ylim()[1] * 0.95, 'Forecast →', color='#F5B027', fontsize=10)

# Styling
ax.set_xlabel('Time Period', color='white', fontsize=11)
ax.set_ylabel('Value', color='white', fontsize=11)
ax.set_title('Demand Forecast with Uncertainty', color='white', fontsize=14, fontweight='bold', pad=15)
ax.tick_params(colors='#888888', labelsize=9)
for spine in ax.spines.values():
    spine.set_color('#333333')
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.legend(facecolor='#0a0a0f', edgecolor='#333333', labelcolor='white', loc='upper left')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support