from matplotlib import pylab as pl import numpy as np #First, we use the NumPy loadtxt function to read our previously saved file containing corresponding values of Tc and lattice size YC_Data_Tc = np.loadtxt("YC_Data_Tc.txt") #Obtain required data from file #Our equation contains the term '1/L' - so we determine the inverse of lattice size: Lattice_size_inverse= (YC_Data_Tc[:,0])**(-1) Tc = YC_Data_Tc[:,1] #Plot Data Points pl.plot(Lattice_size_inverse, Tc, 'ro', label='Data Points Recorded') fit = np.polyfit(Lattice_size_inverse, Tc, 1) #fit a 1 order polynomial (as needed) L_inverse_max = np.max(Lattice_size_inverse) L_inverse_min = np.min(Lattice_size_inverse) L_range = np.linspace(L_inverse_min, L_inverse_max, 1000) #generate 1000 evenly spaced points between L_min and L_max fitted_Tc_values = np.polyval(fit, L_range) # use the fit object to generate the corresponding values of Tc #Plotting 'fitted' data pl.plot(L_range,fitted_Tc_values,'b-', label = 'Fitted curve') pl.title('Plot of Curie Temperature vs Inverse of Lattice Size') pl.ylabel("Curie Temperature") pl.xlabel("Inverse of Lattice Size") pl.legend(loc='best') pl.show() print (np.polyval(fit,0))