Line & Scatter

Signal & Noise

Smooth trend line with noisy scattered data points overlay.

Output
Signal & Noise
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'signal': '#0EA5E9',     # Sky blue - clean signal
    'noise': '#F43F5E',      # Rose - noisy data
    'background': '#FAFBFC',
    'text_muted': '#64748B',
    'grid': '#E2E8F0',
}

# === DATA ===
np.random.seed(42)
x = np.linspace(0, 12, 150)
signal = 3 + 2 * np.sin(0.5 * x) + 0.3 * x

x_samples = np.linspace(0, 12, 40)
noise = 3 + 2 * np.sin(0.5 * x_samples) + 0.3 * x_samples + np.random.normal(0, 0.6, 40)

# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

# === PLOT ===
ax.scatter(x_samples, noise, 
           color=COLORS['noise'], s=40, alpha=0.6,
           edgecolors='white', linewidths=1,
           label='Observations', zorder=2)

ax.plot(x, signal, 
        color=COLORS['signal'], linewidth=2.5,
        label='Trend', zorder=3)

# === AXES ===
ax.set_xlim(0, 12)
ax.set_ylim(0, 9)
ax.set_xlabel('Time', fontsize=10, color=COLORS['text_muted'], labelpad=10)
ax.set_ylabel('Amplitude', 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

Did this help you?

Support PyLucid to keep it free & growing

Support