← retour aux snippets

matplotlib: annotate (flèches)

Ajouter des annotations avec flèches et lignes de repère.

objectif

Ajouter des annotations avec flèches et lignes de repère.

code minimal

import matplotlib.pyplot as plt

plt.plot([0,1,2],[0,1,0])
plt.annotate("max", xy=(1,1), xytext=(1.2,1.2), arrowprops=dict(arrowstyle="->"))
print("annotated")

utilisation

import matplotlib.pyplot as plt

plt.axvline(1, ls="--"); plt.axhline(0.5, ls=":"); print("ref lines")

variante(s) utile(s)

import matplotlib.pyplot as plt

plt.text(0.1, 0.9, "note", transform=plt.gca().transAxes); print("text")

notes

  • arrowprops personnalise style et taille de flèche.