import matplotlib.pyplot as plt

filename = "temperature.xvg"

time = []
temperature = []

with open(filename, "r") as f:
    for line in f:
        if line.startswith("#") or line.startswith("@"):
            continue

        parts = line.split()
        if len(parts) >= 2:
            time.append(float(parts[0]))
            temperature.append(float(parts[1]))

plt.figure(figsize=(10, 6))
plt.plot(time, temperature, color="darkred", linewidth=1.5, label="Temperature")
plt.axhline(y=298, color="navy", linestyle="--", linewidth=1.2, label="Target temperature (298 K)")

plt.xlabel("Time (ps)", fontsize=14)
plt.ylabel("Temperature (K)", fontsize=14)

plt.xticks(fontsize=14)
plt.yticks(fontsize=14)

plt.grid(True, linestyle="--", alpha=0.5)
plt.legend(fontsize=12)

plt.tight_layout()
plt.savefig("temperature_profile.png", dpi=300, bbox_inches="tight")
plt.show()