← retour aux snippets

matplotlib: courbe, nuage, histogramme

Tracer un line plot, un scatter et un histogramme simples.

objectif

Tracer un line plot, un scatter et un histogramme simples.

code minimal

import matplotlib.pyplot as plt

plt.plot([1,2,3], [1,4,9])
plt.scatter([1,2,3], [3,2,1])
plt.hist([1,1,2,3,3,3])
print("plotted")

utilisation

import matplotlib.pyplot as plt

plt.xlabel("x"); plt.ylabel("y"); plt.title("demo"); plt.tight_layout()
print("styled")

variante(s) utile(s)

import matplotlib.pyplot as plt

plt.figure(); plt.bar([1,2,3],[3,1,2]); print("bar")

notes

  • Utiliser plt.show() en local pour afficher.