Chapitre 3: Les graphiques
23/02/2025 Dr Saidi Farah 1
Représentation graphique
Représentation graphique 2D
• Pour tracer un graphe en 2D, on utilise la fonction « plot() », cette
fonction a comme entrée deux vecteur de même taille.
exp:
1. clear all; close all; clc;
2. t=[0:0.01:2*pi];
3. x=cos(t);
4. plot(t,x)
23/02/2025 Dr Saidi Farah 2
Représentation graphique
Représentation graphique 2D
Tracer deux graphe ou plus :
• Dans des fenêtres séparées
• clear all; close all; clc;
• t=[0:0.01:2*pi];
• x=cos(t);
• y=sin(t);
• figure(1)
• plot(t,x)
• figure(2)
• plot(t,y)
23/02/2025 Dr Saidi Farah 3
Représentation graphique
Représentation graphique 2D
Tracer deux graphe ou plus :
• Dans la même fenêtre
• clear all; close all; clc;
• t=[0:0.01:2*pi];
• x=cos(t);
• y=sin(t);
• subplot(1,2,1)
• plot(t,x)
• subplot(1,2,2)
• plot(t,y)
23/02/2025 Dr Saidi Farah 4
Représentation graphique
Représentation graphique 2D
Tracer deux graphe ou plus :
• En superposition
• clear all; close all; clc;
• t=[0:0.01:2*pi];
• x=cos(t);
• y=sin(t);
• plot(t,x)
• hold on
• plot(t,y)
23/02/2025 Dr Saidi Farah 5
Représentation graphique
Représentation graphique 2D
Personnaliser les graphes :
xlabel, ylabel : ajouter un texte à coté de l’axe x et l’axe y
title : ajouter un titre pour le graphe
grid : lignes de quadrillage
legend : crée une légende avec des étiquettes descriptives pour chaque série de données
tracées.
• clear all; close all; clc;
• t=[0:0.1:10*pi];
• x=cos(t);
• plot(t,x)
• grid
• title('le graphe de la fonction cos(t)')
• xlabel('le temps t')
• ylabel('la fonction cos(t)')
23/02/2025 Dr Saidi Farah 6
Représentation graphique
Représentation graphique 2D
Personnaliser les graphes :
• clear all; close all; clc;
• t=[0:0.1:10*pi];
• x=cos(t);
• y=sin(t);
• %plot(t,x,’b.-’,t,y,’r*’)
• plot(t,x,'b.-')
• hold on
• plot(t,y,'r*')
• legend('cos','sin')
• grid
• title('le graphe de la fonction cos(t)')
• xlabel('le temps t')
• ylabel('la fonction cos(t)et sin(t)’)
23/02/2025 Dr Saidi Farah 7
Représentation graphique
Représentation graphique 2D
Personnaliser les graphes :
23/02/2025 Dr Saidi Farah 8
Représentation graphique
Représentation graphique 2D
Représentation spécifique :
• bar: trace les valeurs en barres verticalement ou horizontalement.
• clear all; close all; clc;
• a=[10 20 30 40 50];
• b=[35 42 12 6 99];
• bar(a,b)
• xlabel('a')
• ylabel('b')
23/02/2025 Dr Saidi Farah 9
Représentation graphique
Représentation graphique 2D
Représentation spécifique :
• hist : pour les histogrammes.
• clear all; close all; clc;
• a=[10 20 30 40 50];
• b=[25 35 45 55 65];
• hist(a,b)
• xlabel('a')
• ylabel('b')
23/02/2025 Dr Saidi Farah 10
Représentation graphique
Représentation graphique 2D
Représentation spécifique :
• pie : pour les tracés en secteurs portions
• clear all; close all; clc;
• a=[10 25 15 50];
• pie(a)
23/02/2025 Dr Saidi Farah 11
Représentation graphique
Représentation graphique 3D
La commande « plot3() » est une fonction utiliser pour le tracée en 3
dimension. Cette commande est similaire à la fonction « plot » sauf on
ajoute un troisième axe z.
• clear all; close all; clc;
• t=[0:0.1:10*pi];
• x=cos(t);
• y=sin(t);
• plot3(t,x,y)
• grid
• title('le graphe de la fonction cos(t)')
• xlabel('le temps t')
• ylabel('la fonction cos(t)')
• zlabel('la fonction sin(t)')
23/02/2025 Dr Saidi Farah 12
Représentation graphique
Représentation graphique 3D
• clear all; close all; clc;
• x = -10:0.1:10;
• y = -5:0.1:5;
• [X,Y] = meshgrid(x,y);
• Z= exp(-X.^2).*exp(-Y.^2);
• figure(1)
• surf(x,y,Z)
• figure(2)
• mesh(x,y,Z)
• figure(3)
• pcolor(x,y,Z)
• figure(4)
• contour(x,y,Z)
23/02/2025 Dr Saidi Farah 13
Représentation graphique
Représentation graphique 3D
• figure(1)
• surf(x,y,Z)
23/02/2025 Dr Saidi Farah 14
Représentation graphique
Représentation graphique 3D
• figure(2)
• mesh(x,y,Z)
23/02/2025 Dr Saidi Farah 15
Représentation graphique
Représentation graphique 3D
• figure(3)
• pcolor(x,y,Z)
23/02/2025 Dr Saidi Farah 16
Représentation graphique
Représentation graphique 3D
• figure(4)
• contour(x,y,Z)
23/02/2025 Dr Saidi Farah 17