File size: 1,396 Bytes
d323f57 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import numpy as np
import matplotlib.pyplot as plt
# ── Parameters ──────────────────────────────────────────────────────────────
seed = 5908
n_points = 53
slope = 1.044824
intercept = 0.686445
noise_std = 0.641637
# ── Data ────────────────────────────────────────────────────────────────────
rng = np.random.default_rng(seed)
x = np.sort(rng.uniform(-3.0, 3.0, n_points))
y = slope * x + intercept + rng.normal(0.0, noise_std, n_points)
x_line = np.array([-3.0, 3.0])
y_line = slope * x_line + intercept
# ── Plot ─────────────────────────────────────────────────────────────────────
fig, ax = plt.subplots(figsize=(6, 5))
ax.scatter(x, y, alpha=0.6, s=30, color="steelblue", zorder=2)
ax.plot(x_line, y_line, color="crimson", linewidth=2, zorder=3,
label=f"y = {slope:.3f}x + {intercept:.3f}")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_title(f"Linear Scatter (n={n_points})")
ax.legend(fontsize=9)
ax.grid(True, alpha=0.3)
fig.tight_layout()
plt.show()
|