Exemple de diagramme en bâtons avec deux couleurs sous Matplotlib en utilisant bar:

import matplotlib.pyplot as pltimport pylab as plimport numpy as npcounts_01 = [8,12,8,5,4,3,2,1,0,0]counts_02 = [5,10,12,15,11,10,8,5,3,2]fig = plt.figure()ax = fig.add_subplot(111)ind = np.arange(0,1,0.1)width = 0.1rects1 = ax.bar(ind+width/2.0, counts_01, width/2.0, color=(0.65098041296005249, 0.80784314870834351, 0.89019608497619629, 1.0), label='1')rects2 = ax.bar(ind, counts_02, width/2.0, color=(0.69411766529083252, 0.3490196168422699, 0.15686275064945221, 1.0), label='2')ax.set_ylabel('Counts')pl.legend()plt.savefig('BarsTwoColors.png')plt.show()
Recherches associées
| Liens | Site |
|---|---|
| pyplot | matplotlib doc |
| Matplotlib - label each bin | stackoverflow |
| Aligning rotated xticklabels with their respective xticks | stackoverflow |
| How to add an integer to each element in a list? | stackoverflow |
| matplotlib set yaxis label size | stackoverflow |
| pylab_examples example code: barchart_demo2.py | matplotlib example |
