Rep:Mod:DMS3053-9
Appearance
from matplotlib import pylab as pl import numpy as np
def extract_data(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(file) fit = np.polyfit(file_data[0], file_data[1], 11) # fit a third order polynomial T_min = np.min(file_data[0]) T_max = np.max(file_data[0]) T_range = np.linspace(T_min, T_max, 1000) #generate 1000 evenly spaced points between T_min and T_max fitted_C_values = np.polyval(fit, T_range) # use the fit object to generate the corresponding values of C pl.ylabel("Heat Capacity") pl.xlabel("Temperature") pl.ylim([0.0, 1.5]) 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()