Avec matplotlib on peut facilement tracer une boîte à moustaches avec la fonction boxplot, illustration:

import matplotlib.pyplot as pltdata = [1,2,3,4,5,6,7,8,9]plt.boxplot(data)plt.ylim(0,10)plt.savefig('SimpleBoxPlot.png')plt.show()
Note: par défaut sous matplotlib les extrémités ('caps' en anglais) des moustaches ('whiskers' en anglais) sont placées à $Q1 - 1.5 * IQR$ et $Q3 + 1.5 * IQR$ avec IQR interquartile range (Écart interquartile). Les points ('fliers' en anglais) en dehors de ces limites sont représentés par une croix:

import matplotlib.pyplot as pltdata = [1,2,3,4,5,6,7,8,9,20]plt.boxplot(data)plt.ylim(0,25)plt.savefig('SimpleBoxPlot02.png')plt.show()
Exemple avec plusieurs boîtes à moustaches:

import matplotlib.pyplot as pltimport pylabdata_01 = [1,2,3,4,5,6,7,8,9]data_02 = [15,16,17,18,19,20,21,22,23,24,25]data_03 = [5,6,7,8,9,10,11,12,13]BoxName = ['data 01','data 02','data 03']data = [data_01,data_02,data_03]plt.boxplot(data)plt.ylim(0,30)pylab.xticks([1,2,3], BoxName)plt.savefig('MultipleBoxPlot02.png')plt.show()
Recherches associées
| Liens | Site |
|---|---|
| boxplot | matplotlib doc |
| pylab_examples example code: boxplot_demo.py | matplotlib doc |
| Interpreting weird box plot with reversed whiskers | stats stackexchange |
| Boîte à moustaches | wikipedia |
| matplotlib boxplot color | stackoverflow |
