Rep:Mod:DMS3053-10
Appearance
from matplotlib import pylab as pl import numpy as np
def extract_data_c(file):
data_array = np.loadtxt(file)
temps = data_array[:,0]
heat_cap_per_spin = data_array[:,5]
return temps, heat_cap_per_spin
def plotdata(file):
file_data = extract_data_c(file)
T_min = 2.15
T_max = 2.55 # Min and Max altered to get good peak fit
T_range = np.linspace(T_min, T_max, 1000) #g= Generates 1000 evenly spaced points between T_min and T_max
selection = np.logical_and(file_data[0] > T_min, file_data[0] < T_max) # Selects rows of data for which both conditions are met
peak_T_values = file_data[0][selection] # Selects the appropriate temperature values
peak_C_values = file_data[1][selection] # Selects the appropriate heat capacity values
fit = np.polyfit(peak_T_values, peak_C_values, 3) # Fits a third order polynomial
fitted_C_values = np.polyval(fit, T_range) # Uses the fit object to generate the corresponding values of C
Cmax = np.max(fitted_C_values) # Locates the maximum in heat capacity
Tmax = T_range[fitted_C_values == Cmax] # Locates the corresponding value of temperature
pl.ylabel("Heat Capacity")
pl.xlabel("Temperature")
pl.ylim([0.0, 2.0])
pl.plot(file_data[0], file_data[1], T_range, fitted_C_values)
pl.legend(['Data', 'Polynomial fit'], loc='upper center', bbox_to_anchor=(0.5, 1.10),
ncol=5)
pl.show()
print(Cmax)
print(Tmax)