0% ont trouvé ce document utile (0 vote)
24 vues4 pages

Matplotlib Subplot

Transféré par

maymoun jabnouni
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
24 vues4 pages

Matplotlib Subplot

Transféré par

maymoun jabnouni
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
Vous êtes sur la page 1/ 4

Matplotlib Subplot LSE3

Exemple_1
Afficher plusieurs tracés
Avec la fonction subplot() vous pouvez dessiner plusieurs tracés sur une
seule figure :
import matplotlib.pyplot as plt
import numpy as np

#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(1, 2, 1)
plt.plot(x,y)

#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(1, 2, 2)
plt.plot(x,y)

plt.show()

La fonction subplot() prend trois arguments qui décrivent la disposition de


la figure.
La mise en page est organisée en lignes et colonnes, représentées par le
premier et le deuxième argument.
Le troisième argument représente l'index du tracé actuel.
plt.subplot(1, 2, 1)
La figure a 1 ligne, 2 colonnes, et ce tracé est le premier tracé.
plt.subplot(1, 2, 2)
 La figure a 1 ligne, 2 colonnes, et ce tracé est le deuxième tracé.

Hammadi Oumaima
Matplotlib Subplot LSE3

Exemple_2 :
Ainsi, si nous voulons une figure avec 2 lignes et 1 colonne (ce qui signifie
que les deux tracés seront affichés l'un sur l'autre au lieu de côte à côte),
nous pouvons écrire la syntaxe comme celle-ci :
#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(2, 1, 1)
plt.plot(x,y)

#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(2, 1, 2)
plt.plot(x,y)

plt.show()

Exemple_3:
Vous pouvez dessiner autant de tracés que vous le souhaitez sur une seule
figure, décrivez simplement le nombre de lignes, de colonnes et l'index du
tracé.
import matplotlib.pyplot as plt
import numpy as np

x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(2, 2, 1)
plt.plot(x,y)

x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(2, 2, 2)
plt.plot(x,y)

x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

Hammadi Oumaima
Matplotlib Subplot LSE3

plt.subplot(2, 2, 3)
plt.plot(x,y)

x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(2, 2, 4)
plt.plot(x,y)

plt.show()

Exemple_4:
*Titre
Vous pouvez ajouter un titre à chaque tracé avec la fonction title() :

#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(1, 2, 1)
plt.plot(x,y)
plt.title("VENTES")

#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(1, 2, 2)
plt.plot(x,y)
plt.title("REVENU")

plt.show()

Exemple_5 :
*sous-titre
Vous pouvez ajouter un titre à la figure entière avec la fonction suptitle() :
#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

Hammadi Oumaima
Matplotlib Subplot LSE3

plt.subplot(1, 2, 1)
plt.plot(x,y)
plt.title("VENTES")

#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(1, 2, 2)
plt.plot(x,y)
plt.title("REVENU")

plt.suptitle("MON MAGASIN")
plt.show()

Hammadi Oumaima

Vous aimerez peut-être aussi