| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # ── Parameters ───────────────────────────────────────────────────────────── | |
| seed = 1907 | |
| size = 42 | |
| colormap = "viridis" | |
| n_blobs = 3 | |
| # ── Data ──────────────────────────────────────────────────────────────────── | |
| x = np.linspace(-3.0, 3.0, size) | |
| y = np.linspace(-2.0, 4.0, size) | |
| X, Y = np.meshgrid(x, y) | |
| Z = np.zeros((size, size)) | |
| Z += 0.592669 * np.exp( | |
| -((X - 1.216654)**2 / (2 * 1.417214**2) | |
| + (Y - -0.698115)**2 / (2 * 1.244495**2)) | |
| ) | |
| Z += 1.383131 * np.exp( | |
| -((X - 0.968027)**2 / (2 * 0.864172**2) | |
| + (Y - 0.815769)**2 / (2 * 1.395209**2)) | |
| ) | |
| Z += 1.402953 * np.exp( | |
| -((X - 1.965273)**2 / (2 * 0.779246**2) | |
| + (Y - 1.011683)**2 / (2 * 1.077274**2)) | |
| ) | |
| # ── Plot ──────────────────────────────────────────────────────────────────── | |
| fig, ax = plt.subplots(figsize=(6, 5)) | |
| im = ax.pcolormesh(X, Y, Z, cmap=colormap, shading="auto") | |
| fig.colorbar(im, ax=ax, label="Intensity") | |
| ax.set_title(f"Gaussian Heatmap ({n_blobs} blob(s))") | |
| ax.set_xlabel("X") | |
| ax.set_ylabel("Y") | |
| fig.tight_layout() | |
| plt.show() | |