import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import math
import scipy.optimize
import random as rd



# file = 'C:/Users/gluca/OneDrive/Documents/ENS/Agregation/Oral/Montage/Polarisation des ondes electromagnetiques/brewster.txt'

SMALL_SIZE = 15
MEDIUM_SIZE = 20
BIGGER_SIZE = 12

plt.rc('font', size=SMALL_SIZE)          # controls default text sizes
plt.rc('axes', titlesize=SMALL_SIZE)     # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('legend', fontsize=MEDIUM_SIZE)    # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title


def notion_sci(x,dx):
    n0=np.log10(np.abs(x))
    if n0>0:
        n = int(n0)
    else:
        n = int(n0-1)
    xx = x/(10**n)
    dxx = dx/(10**n)
    return([xx,dxx,n])
##

fichier = open("meas0002.csv", 'r')
fichier.readline()  #pour la première ligne des noms

R = []
pas = 0.33


for ligne in fichier:
    ligne_splitee = ligne.split(';')
    if ligne_splitee[0] !="":
        R.append(float(ligne_splitee[0].replace(',','.')))
        R[-1] = R[-1]*(10**float(ligne_splitee[1]))

fichier.close()
t = [i*pas for i in range(len(R))]
R=np.array(R)
t = np.array(t)

plt.figure()


# plt.errorbar(I, U, yerr=delta_U, xerr=delta_I ,label = 'Donnée', ecolor='C1',elinewidth=1.5, linestyle = 'none', marker = '.', markersize=2,mfc='C0',capsize = 5)

plt.plot(t, R, label="Résitance",color='C0')


# car1 = r"$n$ =({:.2f}$\pm${:.2f})$ \times $ $ 10^{{{:d}}}$ ".format(not_n[0],not_n[1],not_n[2])
# plt.text(0.8,3,car1, va="top", ha="left")

plt.legend()
plt.ylabel(r"$R (\Omega)$")
plt.xlabel(r"t (s) ")
plt.show()
