1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| # -*- coding: cp1252 -*-
import matplotlib.pyplot as plt
import pylab
import numpy
tabx = []
taby = []
# Avoir le jeu de data
while True:
x = raw_input("Enter X ") #Lance l'application#
y = raw_input("Enter Y ")
tabx.append(float(x)) #Dit que ça peut être des nombres flottants#
taby.append(float(y))
another = raw_input("Continue ? y/n \n") #donne condition pour poursuivre l'app#
if another != "y":
break
# Tant qu'on met "y", l'application continue de fonctionner#
time_min = 0.1
time_max = 30
#axes horizontaux
a,b = pylab.polyfit(tabx, taby, 1)
# calcul du moindre carre
def droite_moindre_carre(x):
return a * x + b
x_moindre_carre = numpy.linspace(min(tabx), max(tabx), 100)
#linspace(a,b,n) => fournit une liste de valeurs de a à b, en n étapes
y_moindre_carre = map(droite_moindre_carre, x_moindre_carre)
# calcul des valeurs de la courbe de moindres carrés
# map => Utilise une fonction sur chaque element d'une liste
plt.axis([time_min, time_max,0,100])
plt.plot(tabx, taby, 'or')
# o => point, r => red
plt.plot(x_moindre_carre, y_moindre_carre, 'b')
# b = blue, pas de o => line
plt.show()
# trace le graphique |
Partager