2 Dimensional Ising Model Simulate the change in energy and magnetization in a ferro magnet

Loading...
Searching...
No Matches
pd_estimate.py
1 import os
2 from pathlib import Path
3
4 import matplotlib.pyplot as plt
5 import numpy as np
6
7
8 def plot(infile, outfile):
9 if not (outdir := Path(outfile).parent).exists():
10 os.makedirs(outdir)
11
12 figure1, ax1 = plt.subplots()
13 arr = []
14 with open(infile) as f:
15 lines = f.readlines()
16 for line in lines:
17 vals = line.strip().split(",")
18 arr.append(float(vals[0]))
19
20 ax1.hist(arr, np.arange(min(arr), max(arr) + 0.02, 0.02), density=True, ec="black")
21
22 figure1.savefig(outfile)
23
24
25 if __name__ == "__main__":
26 plot("output/pd_estimate/estimate_1_0.txt", "../latex/images/pd_estimate_1_0.pdf")
27 plot("output/pd_estimate/estimate_2_4.txt", "../latex/images/pd_estimate_2_4.pdf")