
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.interpolate import griddata

df = pd.read_csv("../data/measurements.csv")

z0 = 0
t0 = 5

subset = df[
    (df["z"].between(z0 - 0.6, z0 + 0.6)) &
    (df["time"].between(t0 - 0.6, t0 + 0.6))
]

xi = np.linspace(-5, 5, 100)
yi = np.linspace(-5, 5, 100)

X, Y = np.meshgrid(xi, yi)

Z = griddata(
    (subset["x"], subset["y"]),
    subset["temperature"],
    (X, Y),
    method="linear"
)

fig, ax = plt.subplots(figsize=(10, 8))

contour = ax.contourf(
    X, Y, Z,
    levels=25,
    cmap="inferno"
)

ax.contour(
    X, Y, Z,
    levels=10,
    colors="white",
    linewidths=0.5,
    alpha=0.5
)

fig.colorbar(
    contour,
    ax=ax,
    label="Temperature [°C]"
)

ax.set_xlabel("X")
ax.set_ylabel("Y")

ax.set_title(
    f"Spatial Temperature Field | Z={z0}, Time={t0}"
)

ax.set_aspect("equal")
plt.tight_layout()
plt.savefig("../lectures/imgs/mpl_04.png")
plt.show()
