Avec matplotlib on peut facilement ajouter manuellement sur une simple figure une légende avec du texte et une boîte de couleur avec le module patches, exemple:

import matplotlib.patches as mpatchesimport matplotlib.pyplot as pltred_patch = mpatches.Patch(color='red', label='The red data')plt.legend(handles=[red_patch])plt.savefig("proxy_artists.png")plt.show()
Un autre exemple:

import matplotlib.pyplot as pltimport scipy.statsimport numpy as npx_min = 0.0x_max = 30.0#----------------------------------------------------------------------------------------## Population Bmean = 9.0std = 2.0x = np.linspace(x_min, x_max, 100)y = scipy.stats.norm.pdf(x,mean,std)plt.plot(x,y, color='black')plt.fill_between(x, y, color='#89bedc', alpha='1.0')#----------------------------------------------------------------------------------------## Population Amean = 15.0std = 4.0x = np.linspace(x_min, x_max, 100)y = scipy.stats.norm.pdf(x,mean,std)plt.plot(x,y, color='black')plt.fill_between(x, y, color='#0b559f', alpha='1.0')#----------------------------------------------------------------------------------------## legendimport matplotlib.patches as mpatchespop_a = mpatches.Patch(color='#0b559f', label='Population A')pop_b = mpatches.Patch(color='#89bedc', label='Population B')plt.legend(handles=[pop_a,pop_b])#----------------------------------------------------------------------------------------#plt.grid()plt.xlim(x_min,x_max)plt.ylim(0,0.25)plt.title('How to use ROC curve to test a dicrete classifier ?',fontsize=10)plt.xlabel('x')plt.ylabel('Probability Density Function')plt.savefig("roc_curve_discrete_classifier_02.png")plt.show()
Références
| Links | Site |
|---|---|
| Proxy artists | matplotlib doc |
