Exemples de comment tracer une simple ligne horizontale avec matplotlib de python:
Table des matières
Tracer une ligne horizontale
Pour tracer une simple ligne horizontale dans une figure matplotlib on peut utiliser axhline, illustration

import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0, 2*np.pi, 1000)y1 = np.sin(x)f = plt.figure()ax = f.add_subplot(111)plt.plot(x, y1)plt.axhline(y=0.5)plt.axhline(y=-0.5)plt.title('How to plot a vertical line with matplotlib ?', fontsize=8)plt.xlim(0, 2.0*np.pi)plt.ylim(-1.5, 1.5)plt.savefig('matplotlib_horizontal_line_03.png', bbox_inches='tight')plt.show()
Changer la couleur
plt.axhline(y=0.5,color='gray')

Mettre la ligne en pointillée
plt.axhline(y=0.5,color='gray',linestyle='--')

Références
| Liens | Site |
|---|---|
| matplotlib.pyplot.axhline | matplotlib.org |
| Python matplotlib.pyplot.axhline() Examples | programcreek.com |
