Changer la Taille d’une Figure avec Matplotlib

Problème:

Comment changer la taille d’une figure créée à partir de Matplotlib?

Solution:

Utiliser matplotlib.pyplot.figure et jouer sur le paramètre figsize.

Exemple:

# Importations.
import matplotlib.pyplot as plt
# Valeurs pour l'exemple.
x = [3, 1, 4, 6, 7]
y = [2, 4, 7, 5, 4]
# Tracé.
plt.scatter(x, y)
plt.show()
fig = plt.figure(figsize=(8, 8))
plt.scatter(x, y)
plt.show()
Image d'un tracé fait avec Matplotlib sans modification de taille
Aucune modification de taille
Image d'un tracé fait avec Matplotlib après modification de taille
Nouvelle taille

Laisser un commentaire