Area Chart

Confidence Band

Regression with 68% and 95% confidence intervals.

Output
Confidence Band
Python
import matplotlib.pyplot as plt
import numpy as np

# Data - Linear regression with confidence intervals
np.random.seed(42)
x = np.linspace(0, 10, 50)
y_true = 2 + 0.5 * x
noise = np.random.normal(0, 0.5, len(x))
y = y_true + noise

# Fit and intervals
from numpy.polynomial import polynomial as P
coef = np.polyfit(x, y, 1)
y_fit = np.polyval(coef, x)
residuals = y - y_fit
se = np.std(residuals)

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

# Confidence bands with NEON purple
ax.fill_between(x, y_fit - 2*se, y_fit + 2*se, alpha=0.2, color='#4927F5', label='95% CI')
ax.fill_between(x, y_fit - se, y_fit + se, alpha=0.4, color='#4927F5', label='68% CI')
ax.plot(x, y_fit, color='#F5276C', linewidth=2.5, label='Fit')
ax.scatter(x, y, color='#27D3F5', s=40, alpha=0.8, edgecolors='white', linewidth=0.3)

# Styling
ax.set_xlabel('X Variable', color='white', fontsize=11)
ax.set_ylabel('Y Variable', color='white', fontsize=11)
ax.set_title('Linear Fit with Confidence Intervals', 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