Avec matplotlib vous pouvez changer la couleur d'un bâton d'un diagramme en bâtons pour mettre ce dernier en évidence comme dans cet exemple:

import matplotlib.pyplot as pltfig = plt.figure()x = [1,2,3,4,5,6,7,8,9]y = [2,3,5,7,8,5,4,3,2]bars = plt.bar(x, y, color='blue' )bars[6].set_facecolor('red')plt.savefig('BarHighlight.png')plt.show()
Un exemple plus complexe (télécharger le fichier [attachment:498]):

import matplotlib.pyplot as pltimport numpy as npimport pylabx,height = np.loadtxt("MutualInformation.txt", unpack=True)ModisCloudMaskBandUsed = ['1','2','5','6','18','19','26','20','21','27','29','31','32','35']BarName = [ '1','2','3','4','5','6','7','8','9','10','11','12','13lo','13hi','14lo','14hi','15','16','17','18','19','26','20','21','22','23','24','25','27','28','29','30','31','32','33','34','35','36']fig = plt.figure()width = 0.75bars = plt.bar(x, height, width, color=(0.65098041296005249, 0.80784314870834351, 0.89019608497619629, 1.0) )for i in ModisCloudMaskBandUsed:index = BarName.index(i)print i, indexbars[index].set_facecolor((0.69411766529083252, 0.3490196168422699, 0.15686275064945221, 1.0))plt.xlim(1,39)plt.ylim(0,1)plt.grid()plt.ylabel('Mutual Information')pylab.xticks(x+0.5, BarName, rotation=90)plt.bar(1, 0, 0.0,color=(0.69411766529083252, 0.3490196168422699, 0.15686275064945221, 1.0),label='Bands Used in MODIS Cloud Mask')plt.legend(prop={'size':12})plt.savefig('MutualInformation.png',bbox_inches='tight')plt.show()
Recherches associées
| Liens | Site |
|---|---|
| matplotlib - changing rect colours on the fly | stackoverflow |
