# Initializing some things import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt import matplotlib as mpl import matplotlib.animation as animation %matplotlib inline mpl.rcParams['lines.linewidth'] = 1.5 mpl.rcParams['lines.marker'] = "o" mpl.rcParams['axes.grid'] = True mpl.rcParams['legend.labelspacing'] = 0.0 cmap = mpl.cm.get_cmap(name='YlOrRd') colors3 = [cmap(x) for x in [0.4, 0.6, 0.9]] ax = plt.subplot(xlabel="Energy", ylabel="Probability", title="Boltzmann distribution") E = np.linspace(0, 4.5, num=50) for i, T in enumerate([0.8, 1.5, 3.5]): ax.plot(E, 1.0/T*np.exp(-E/T), "-", label="T={}".format(T), color=colors3[i]) ax.legend(); # !magneto -N1=20000 -N2=0 -TMin=1.3 -TMax=3.3 -L=62 -TSteps=3 -states=states def draw_state(ax, grid, title): ax.grid(False) ax.imshow(grid, cmap=plt.cm.Greys, interpolation="none") ax.set_title(title) def load_states(filename): with open(filename) as f: T = float(f.readline()) grid = np.loadtxt(filename, delimiter=",", skiprows=1) return T, grid def draw_states(filename_base, n=3): fig = plt.figure(figsize=(3*n, n)) for i in range(n): T, grid = load_states(filename="{}{}.txt".format(filename_base, i)) ax = fig.add_subplot(1, n, i+1) draw_state(ax, grid, "T={:.2f}".format(T)) fig.tight_layout() draw_states("states", 3) # !magneto -L=30 -TSteps=15 -en=energy -dist=normal -alg=sw -N1=10 -N2=100 Tc = 2.0/np.log(1+np.sqrt(2)) ax = plt.subplot(xlabel="T/T_c", ylabel="Energy", ylim=(-2,0), xlim=(0,2)) T, E = np.loadtxt("energy.txt", delimiter=", ", unpack=True) ax.plot(T/Tc, E); # !magneto -L=30 -TSteps=12 -cv=cv -dist=normal ax = plt.subplot(xlabel="T/T_c", ylabel="Heat capacity") # variance T, cv = np.loadtxt("cv.txt", delimiter=", ", unpack=True) ax.plot(T/Tc, cv, label="by variance") # derivation T, E = np.loadtxt("energy.txt", delimiter=", ", unpack=True) ax.plot(T[:-1]/Tc, np.diff(E)/np.diff(T), label="by derivation") ax.legend(); # !magneto -L=30 -TSteps=12 -N2=200 -mag=mag -dist=normal ax = plt.subplot(xlabel="T/T_C", ylabel="Magnetization |m|", xlim=(0,2), ylim=(0,1)) T, m = np.loadtxt("mag.txt", delimiter=", ", unpack=True) ax.plot(T/Tc, m); # !magneto -L=60 -TSteps=9 -TMin=2.0 -TMax=2.6 -N2=100 -N3=1000 -corr=chi_corrfun -alg=metro -N1=5000 def corr_fun(x, corr_len, a): return np.exp(-x/corr_len)*a def ln_corr_fun(x, corr_len, a): return -x/corr_len + np.log(a) def lower_range(data, threshold): end_index = np.argmax(data # !magneto -N1=0 -N3=1 -N2=5 -TMin=2.3 -L=80 -TSteps=1 -states=slowdown_sw -initial=circle.txt -record=main -alg=sw fig = plt.figure(figsize=(9,3)) data = np.loadtxt("slowdown_sw0.txt", delimiter=",", skiprows=1) L = data.shape[1] grids = np.split(data, data.shape[0]/L) for i in range(3): ax = fig.add_subplot(1, 3, i+1) ax.grid(False) ax.imshow(grids[i], cmap=plt.cm.Greys, interpolation="none") fig.tight_layout()