Scatter Plot
Polynomial Regression
Quadratic fit with confidence band and glow effect.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'points': '#6366F1',
'trend': '#EF4444',
'confidence': '#EF4444',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
# === DATA ===
np.random.seed(42)
x = np.linspace(0, 10, 50)
y = 0.5 * x**2 - 2*x + 5 + np.random.normal(0, 3, 50)
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT ===
# Polynomial fit (degree 2)
z = np.polyfit(x, y, 2)
p = np.poly1d(z)
x_smooth = np.linspace(0, 10, 100)
# Confidence band
residuals = y - p(x)
std_err = np.std(residuals)
ax.fill_between(x_smooth, p(x_smooth) - 2*std_err, p(x_smooth) + 2*std_err,
color=COLORS['confidence'], alpha=0.1, zorder=1)
# Trend line with glow
ax.plot(x_smooth, p(x_smooth), color=COLORS['trend'], linewidth=6, alpha=0.2, zorder=2)
ax.plot(x_smooth, p(x_smooth), color=COLORS['trend'], linewidth=2.5,
label='Polynomial fit', zorder=3)
# Points with glow
ax.scatter(x, y, s=120, c=COLORS['points'], alpha=0.15, zorder=4)
ax.scatter(x, y, s=50, c=COLORS['points'], alpha=0.8,
edgecolors='white', linewidths=1.5, zorder=5)
# === STYLING ===
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color(COLORS['grid'])
ax.spines['bottom'].set_color(COLORS['grid'])
ax.yaxis.grid(True, color=COLORS['grid'], linewidth=1)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.set_xlabel('X', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Y', fontsize=10, color=COLORS['text'], labelpad=10)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Scatter Plot examples
☕