| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # ── Parameters ───────────────────────────────────────────────────────────── | |
| seed = 1901 | |
| size = 27 | |
| colormap = "plasma" | |
| 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 += -1.909467 * np.exp( | |
| -((X - 0.009287)**2 / (2 * 1.277628**2) | |
| + (Y - 2.744406)**2 / (2 * 0.629802**2)) | |
| ) | |
| Z += 0.714654 * np.exp( | |
| -((X - -0.036967)**2 / (2 * 0.752310**2) | |
| + (Y - 2.230718)**2 / (2 * 1.069237**2)) | |
| ) | |
| Z += -1.857357 * np.exp( | |
| -((X - -0.940575)**2 / (2 * 0.504185**2) | |
| + (Y - 0.917902)**2 / (2 * 0.508448**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() | |