Académique Documents
Professionnel Documents
Culture Documents
TP N°1:
Nous allons utiliser matplotlib pour tracer nos fonctions pour importer les modules
matplotlib et numpy, nous écrivons ces deux lignes de code :
1. x = np.array([1, 2, 4, 5])
2. y = np.array([1, 2, 3, 4])
3. plt.figure(figsize=(8, 5))
4. plt.plot(x,x**2, lw=3, marker="o", color='red', ls="dotted", label="courbe 1")
5. plt.plot(y, np.sin(y) , lw=3, marker="o", color="green", label="courbe 2")
6. plt.legend(loc="upper left")
7. plt.title("Statistics of students joining ISSATSo")
8. plt.xlabel("Years")
9. plt.ylabel("Students")
10.
11. plt.savefig("stiisat")
12.
13. plt.show()
14.
1
Exercice 1 :
Le tableau présente le prix des ordinateurs Lenovo et dell durant les cinq derniere
années :
2
Exercice 2 :
1. import matplotlib.pyplot as plt
2. import numpy as np
3. sangammes = np.array(["O", "A", "B", "AB", "Total"])
4. effectifs = np.array([5, 10, 4, 6, 25])
5.
6. plt.bar(sangammes, effectifs, color="blue")
7. plt.title("La repartition des groupes sanguines des eleves")
8. plt.xlabel("Groupes sanguines")
9. plt.ylabel("Effectives")
10. plt.savefig("repart-sang")
11. plt.show()
3
Exercice 3:
1. import matplotlib.pyplot as plt
2. import numpy as np
3.
4. Labels = ["Action", "Aventure", "Sport", "Strategie", "Jeu de role"]
5. Colors = ["yellowgreen", "gold", "lightskyblue", "lightcoral", "blue"]
6. Telechargement = np.array([1400, 600, 506, 1608, 730])
7.
8. plt.pie(Telechargement, labels=Labels, colors=Colors, autopct="%1.1f")
9. plt.legend()
10. plt.title("La repsentation des telechargement de jeux par genre")
11. plt.show()
Représenter ces données sur un histogramme en découpent l'axe des absc en train
intervalles selon le taux de de 60 à 100 et de 120 à 151
4
TP N°2 : Utilisation de module random
Ont peut utiliser random pour générer des valeur aléatoires, on a les fonctions
randint et randrange :
1. import random
2. x = random.randint(1, 10); # variable x appartient à l’intervalle I=[1, 10]
3. y = random.randrange(10); # variable y appartient à l’intervalle I=[1, 10
5. print(x)
6. print(y)
1. x = random.random()
2. print(x)
3. y = random.uniform(1, 10)
4. print(y)
On peut utiliser math.floor(x) pour trouver la plus grande valeur entière inférieur ou
égale à un nombre donné x.
1. import math
2. math.floor(y)
Exemple: Ecrire la partie entière d'un nombre aléatoire dans l'intervalle [0, 16]
Méthode 1 : Méthode 2 :
1. import random 1. import random
2. random.randint(0, 16) 2. import math
3. math.floor(random.uniform(0, 17))
5
choice(a): retourne un element aleatoire de la liste a
1. import random
2. import math
3. def uniforme(a, b):
4. return (a + math.floor(random.random() * ((b - a) + 1)))
6
Traçage de distribution de la loi binomiale:
7
TP N°3:
Distribution binomiale pour n= 10, p=0.5
8
Distribution loi de poisson :