import numpy as np
import matplotlib.pyplot as plt

# Valeurs experimentales (a completer avec vos valeurs)
C = np.array([100,150,200,1000]) 
tau = np.array([110,165,180,987])
u_tau = np.array([12,18,22,50])

# Calcul de la regression lineaire tau = aC + b
p, cov = np.polyfit(C,tau,1, cov = True) #regression lineaire
tau_th = p[0]*C + p[1] #calcul du modele
u_a = np.sqrt(np.diag(cov))[0] #calcul de l incertitude-type sur a
u_b = np.sqrt(np.diag(cov))[1] #calcul de l incertitude-type sur b

# Graphe
label1 = f'Modele : a = {p[0]:.2f} $\pm$ {2*u_a:.2f}, b = {p[1]:.2f} $\pm$ {2*u_b:.2f}'
plt.figure()
plt.errorbar(C,tau,yerr=2*u_tau,fmt='o', label='Experience', color = 'b')
plt.plot(C, np.polyval(p,C), label = label1, color = 'r') #modele
plt.xlabel('$C$ (nF)')
plt.ylabel('tau ($\mu$s)' )
plt.grid()
plt.legend()
plt.title('Trace de la constante de temps en fonction de la capacite du condensateur')
plt.show()