Simple exemple sur comment ajouter une légende à une figure sous matplotlib
[image:matplotlib-legend]
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0, 40, 1000)y1 = np.sin(x)y2 = np.cos(x)plt.plot(x, y1, '-b', label='sine')plt.plot(x, y2, '-r', label='cosine')plt.legend(loc='upper left')plt.title('Matplotlib Legend Example')plt.ylim(-1.5, 2.0)plt.savefig('matplotlib_legend.png', bbox_inches='tight')plt.show()
Recherches associées
| Liens | Site |
|---|---|
| Adding a legend to PyPlot in Matplotlib in the most simple manner possible | stackoverflow |
| Legend guide | matplotlib.org |
