Line & Scatter
Line & Scatter Overlay
Smooth trend line combined with scattered data points and connected series.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'primary': '#6366F1', # Indigo - main accent
'secondary': '#10B981', # Emerald - secondary
'tertiary': '#F59E0B', # Amber - tertiary
'background': '#FAFBFC',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#E2E8F0',
}
# === DATA ===
x = np.linspace(0, 10, 100)
y_smooth = 4 + 1.5 * np.sin(1.5 * x)
x_points = np.linspace(0, 10, 12)
y_markers = 4 + 1.5 * np.sin(1.5 * x_points) + np.random.normal(0, 0.3, 12)
y_connected = 2 + 0.8 * np.sin(1.5 * x_points + 1)
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT - Layer by importance ===
# Background layer: connected points (subtle)
ax.plot(x_points, y_connected, 'o-',
color=COLORS['tertiary'], alpha=0.7,
linewidth=1.5, markersize=5,
markerfacecolor='white', markeredgewidth=1.5,
label='Series B', zorder=2)
# Mid layer: scatter markers
ax.scatter(x_points, y_markers,
color=COLORS['secondary'], s=50, alpha=0.8,
edgecolors='white', linewidths=1.5,
label='Observations', zorder=3)
# Top layer: main trend (hero element)
ax.plot(x, y_smooth,
color=COLORS['primary'], linewidth=2.5,
label='Trend', zorder=4)
# === AXES - Minimal and clean ===
ax.set_xlim(0, 10)
ax.set_ylim(0, 7)
ax.set_xlabel('Time', fontsize=10, color=COLORS['text_muted'],
labelpad=10, fontweight='500')
ax.set_ylabel('Value', fontsize=10, color=COLORS['text_muted'],
labelpad=10, fontweight='500')
# === SPINES - Only bottom and left, subtle ===
for spine in ['top', 'right']:
ax.spines[spine].set_visible(False)
for spine in ['bottom', 'left']:
ax.spines[spine].set_color(COLORS['grid'])
ax.spines[spine].set_linewidth(0.8)
# === GRID - Soft, horizontal only ===
ax.yaxis.grid(True, color=COLORS['grid'], linewidth=0.5, alpha=0.7)
ax.xaxis.grid(False)
ax.set_axisbelow(True)
# === TICKS - Clean and readable ===
ax.tick_params(axis='both', colors=COLORS['text_muted'],
labelsize=9, length=0, pad=8)
# === LEGEND - Outside, minimal ===
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
ncol=3, frameon=False, fontsize=9,
labelcolor=COLORS['text_muted'])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Line & Scatter examples
☕