Line & Scatter
Polynomial Interpolation
Smooth polynomial curve fitted through discrete data points.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'spline': '#EC4899', # Pink
'points': '#1E293B', # Slate dark
'background': '#FAFBFC',
'text_muted': '#64748B',
'grid': '#E2E8F0',
}
# === DATA ===
x_points = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
y_points = np.array([1, 3, 2.5, 5, 4.2, 6, 5.5, 7.5, 7, 8.5, 9])
# Polynomial interpolation (degree 5 for smooth curve)
coeffs = np.polyfit(x_points, y_points, 5)
poly = np.poly1d(coeffs)
x_smooth = np.linspace(x_points.min(), x_points.max(), 200)
y_smooth = poly(x_smooth)
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT ===
ax.plot(x_smooth, y_smooth, color=COLORS['spline'], linewidth=2.5,
label='Polynomial fit', zorder=2)
ax.scatter(x_points, y_points, color=COLORS['points'], s=80,
edgecolors='white', linewidths=2,
label='Data points', zorder=3)
# === AXES ===
ax.set_xlim(-0.5, 10.5)
ax.set_ylim(0, 11)
ax.set_xlabel('X', fontsize=10, color=COLORS['text_muted'], labelpad=10)
ax.set_ylabel('Y', fontsize=10, color=COLORS['text_muted'], labelpad=10)
# === STYLING ===
for spine in ['top', 'right']:
ax.spines[spine].set_visible(False)
for spine in ['bottom', 'left']:
ax.spines[spine].set_color(COLORS['grid'])
ax.yaxis.grid(True, color=COLORS['grid'], linewidth=0.5, alpha=0.7)
ax.xaxis.grid(False)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
ncol=2, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Line & Scatter examples
☕