from pathlib import Path import matplotlib.pyplot as plt import numpy as np from scipy.stats import linregress def plot_phase_transition(indir, outdir): files = [ "no_burn_in.txt", "burn_in.txt", ] labels = [ "Without burn-in time", "With burn-in time", ] figure1, ax1 = plt.subplots() figure2, ax2 = plt.subplots() figure3, ax3 = plt.subplots() figure4, ax4 = plt.subplots() for file, label in zip(files, labels): t = [] e = [] m = [] CV = [] X = [] with open(Path(indir, file)) as f: lines = f.readlines() for line in lines: l = line.strip().split(",") t.append(float(l[0])) e.append(float(l[1])) m.append(float(l[2])) CV.append(float(l[3])) X.append(float(l[4])) ax1.plot(t, e, label=label) ax2.plot(t, m, label=label) ax3.plot(t, CV, label=label) ax4.plot(t, X, label=label) figure1.legend() figure2.legend() figure3.legend() figure4.legend() figure1.savefig(Path(outdir, "energy.pdf")) figure2.savefig(Path(outdir, "magnetization.pdf")) figure3.savefig(Path(outdir, "heat_capacity.pdf")) figure4.savefig(Path(outdir, "susceptibility.pdf")) plt.close(figure1) plt.close(figure2) plt.close(figure3) plt.close(figure4) if __name__ == "__main__": plot_phase_transition( "output/test_burn_in_time/", "../latex/images/test_burn_in", )