Rep:Mod:DMS3053-11
Appearance
from matplotlib import pylab as pl import numpy as np from scipy.interpolate import InterpolatedUnivariateSpline
def extract_data(file):
data_array = np.loadtxt(file)
lattice_lengths = data_array[:,0]
inverse_lengths = 1 / lattice_lengths
curie_temps = data_array[:,1]
return inverse_lengths, curie_temps
def plotdata(file):
file_data = extract_data(file)
L_min = np.min(file_data[0])
L_max = np.max(file_data[0])
L_range = np.linspace(L_min, L_max, 1000) # Generates 1000 evenly spaced points between T_min and T_max
L_range1 = np.linspace(0, L_max, 1000) # Range for extrapolation to y-axis
fit = np.polyfit(file_data[0], file_data[1], 1)
fitted_T_values = np.polyval(fit, L_range)
extrapolation = InterpolatedUnivariateSpline(L_range, fitted_T_values, k=1) # Allows for extrapolation of the fit to find intercept accurately
T_values = extrapolation(L_range1) # Calculates the extrapolated temperatures
pl.ylabel("Temperature")
pl.xlabel("1/(Lattice Length)")
pl.ylim([2.2, 2.6])
pl.plot(file_data[0], file_data[1], L_range1, T_values)
pl.legend(['Data', 'Extrapolated linear fit'], loc='upper center', bbox_to_anchor=(0.5, 1.10),
ncol=2)
pl.show()
print(T_values[L_range1 == 0]) # Prints the y-intercept of the graph