import matplotlib
matplotlib.use('nbagg')
import numpy as np
import matplotlib.pyplot as plt
M = np.loadtxt('LoiCharles.txt')
P = 1e5*M[:,0]
T = 10*M[:,1]
p, residuals, rank, singular_values, rcond = np.polyfit(T, P, deg=1, full=True)
T_fit = np.linspace(np.min(T), np.max(T), 100)
P_fit = p[0]*T_fit+p[1]
plt.figure()
plt.plot(T, P, 'rs')
plt.plot(T_fit, P_fit, 'k-')
plt.xlabel(r'$T$ [deg]')
plt.ylabel(r'$P$ [Pa]')
plt.title('T0 = {:.1f} K'.format(p[1]/p[0]))
plt.show()
print('chi^2 =', residuals)
print('T0 =', p[1]/p[0], 'K')