import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as sp


data1 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_energy_T1.csv", sep=',', names = ['eps', 'm', 'cyc'], dtype=np.float64)
data2 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_energy_T1_NO.csv", sep=',', names = ['eps', 'm', 'cyc'], dtype=np.float64)
data3 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_energy_T2.csv", sep=',', names = ['eps', 'm', 'cyc'], dtype=np.float64)
data4 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_energy_T2_NO.csv", sep=',', names = ['eps', 'm', 'cyc'], dtype=np.float64)
data1.replace(',','')
data2.replace(',','')
data3.replace(',','')
data4.replace(',','')
plt.figure(figsize=(10,10))
plt.plot(np.log10(data1['cyc']),data1['eps'], 'r-')
plt.plot(np.log10(data2['cyc']),data2['eps'], 'g-')
plt.plot(np.log10(data3['cyc']),data3['eps'], 'b-')
plt.plot(np.log10(data4['cyc']),data4['eps'], 'k-')
plt.xlabel('log(cycles)', fontsize= 20)
plt.ylabel('expected energy', fontsize = 20)
plt.title('Expectation energy for L = 20x20 against cycles of MCMC', fontsize = 20)
plt.savefig('C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_eps.pdf')
data1 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_energy_T1.csv", sep=',', names = ['eps', 'm', 'cyc'], dtype=np.float64)
data2 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_energy_T1_NO.csv", sep=',', names = ['eps', 'm', 'cyc'], dtype=np.float64)
data3 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_energy_T2.csv", sep=',', names = ['eps', 'm', 'cyc'], dtype=np.float64)
data4 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_energy_T2_NO.csv", sep=',', names = ['eps', 'm', 'cyc'], dtype=np.float64)
data1.replace(',','')
data2.replace(',','')
data3.replace(',','')
data4.replace(',','')
plt.figure(figsize=(10,10))
plt.plot(np.log10(data1['cyc']),data1['m'], 'r-')
plt.plot(np.log10(data2['cyc']),data2['m'], 'g-')
plt.plot(np.log10(data3['cyc']),data3['m'], 'b-')
plt.plot(np.log10(data4['cyc']),data4['m'], 'k-')
plt.xlabel('log(cycles)', fontsize= 20)
plt.xticks(fontsize = 20)
plt.yticks(fontsize = 20)
plt.ylabel('expected magnetization', fontsize = 20)
plt.title('Expectation magnetization for L = 20x20 against cycles of MCMC', fontsize = 20)
plt.savefig('C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/exp_m.pdf')

plt.figure(figsize=(10,10))
plt.hist(data1['eps'],60)
# plt.hist(data2['eps'],40)
plt.xlim(-2 ,0 )
plt.savefig('C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/eps_hist_T1.pdf')
plt.figure(figsize=(10,10))
plt.hist(data3['eps'],60)
# plt.hist(data4['eps'],40)
plt.xlim(-2 ,0 )
plt.savefig('C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/eps_hist_T2.pdf')

data1 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/L_expect_cv.csv", sep=',', names = ['T', 'cv1', 'cv2', 'cv3', 'cv4'], dtype=np.float64)
data2 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/L_expect_xi.csv", sep=',', names = ['T', 'xi1', 'xi2', 'xi3', 'xi4'], dtype=np.float64)
data3 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/L_expect_eps.csv", sep=',', names = ['T', 'eps1', 'eps2', 'eps3', 'eps4'], dtype=np.float64)
data4 = pd.read_csv("C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/L_expect_m.csv", sep=',', names = ['T', 'm1', 'm2', 'm3', 'm4'], dtype=np.float64)
data1.replace(',','')
data2.replace(',','')
data3.replace(',','')
data4.replace(',','')
plt.figure(figsize=(10,10))
plt.scatter(data1['T'],data1['cv1'], label= ' L =40')
plt.scatter(data1['T'],data1['cv2'], marker = "P", label= ' L =60')
plt.scatter(data1['T'],data1['cv3'], marker = "x",  label= ' L =80')
plt.scatter(data1['T'],data1['cv4'], marker = "1",  label= ' L =100')
plt.grid()
plt.legend()
plt.xlabel('Temperature[J/k_b])', fontsize= 20)
plt.xticks(fontsize = 20)
plt.ylabel('Heat Capacity [k_b]', fontsize = 20)
plt.yticks(fontsize = 20)
plt.title('Heat capacity as a function of temperature for different L', fontsize = 20)
plt.savefig('C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/t_cv.pdf')


plt.figure(figsize=(10,10))
plt.scatter(data2['T'],data2['xi1'], label= ' L =40')
plt.scatter(data2['T'],data2['xi2'], marker = "P", label= ' L =60')
plt.scatter(data2['T'],data2['xi3'], marker = "x",  label= ' L =80')
plt.scatter(data2['T'],data2['xi4'], marker = "1",  label= ' L =100')
plt.xlabel('Temperature[J/k_b])', fontsize= 20)
plt.ylabel('Succeptibility [k_b]', fontsize = 20)
plt.xticks(fontsize = 20)
plt.yticks(fontsize = 20)
plt.grid()
plt.legend()
plt.title('Succeptibility as a function of temperature for different L', fontsize = 20)
plt.savefig('C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/t_xi.pdf')


plt.figure(figsize=(10,10))
plt.plot(data3['T'],data3['eps1'], 'r-', label = ' L = 40')
plt.plot(data3['T'],data3['eps2'], 'g-',  label = ' L = 60')
plt.plot(data3['T'],data3['eps3'], 'b-',  label = ' L = 80')
plt.plot(data3['T'],data3['eps4'], 'k-',  label = ' L =100')
plt.xlabel('Temperature[J/k_b])', fontsize= 20)
plt.ylabel('Expected energy [J]', fontsize = 20)
plt.xticks(fontsize = 20)
plt.yticks(fontsize = 20)
plt.grid()
plt.legend()
plt.title('Expected energy as a function of temperature for different L', fontsize = 20)
plt.savefig('C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/t_eps.pdf')


plt.figure(figsize=(10,10))
plt.plot(data4['T'],data4['m1'], 'r-',  label = ' L =40')
plt.plot(data4['T'],data4['m2'], 'g-',  label = ' L =60')
plt.plot(data4['T'],data4['m3'], 'b-' ,  label = ' L =80')
plt.plot(data4['T'],data4['m4'], 'k-',  label = ' L =100')
plt.xlabel('Temperature[J/k_b])', fontsize= 20)
plt.ylabel('Expected magnetization [J]', fontsize = 20)
plt.xticks(fontsize = 20)
plt.yticks(fontsize = 20)
plt.grid()
plt.legend()
plt.title('Expected magnetization as a function of temperature for different L', fontsize = 20)
plt.savefig('C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/t_m.pdf')


L_list = [1/40,1/60,1/80,1/100]
TC_list = [2.290, 2.29, 2.285, 2.27] # Initiell verdi ikke bra!
ons = [2.269]
L_inf = [0]
x = np.linspace(0, 1/40, len(TC_list))
a = sp.linregress(L_list, TC_list)
# print ( a)
plt.figure(figsize = (10,10))
plt.plot(x, a[0]*x+ a [1])
plt.scatter(L_list, TC_list)
plt.scatter(L_inf, ons, marker='x')
plt.xlabel('1/L', fontsize = 20)
plt.ylabel('$T_C [J]$', fontsize = 20)
plt.xticks(fontsize = 20)
plt.yticks(fontsize = 20)
plt.title('Approximation to Onsagers critical temperature, $T_C$')
plt.grid()
plt.savefig('C:/Users/Lenovo/Documents/Høst22/FYS4150/Prosjekt4/onsager.pdf')
