Exemple de comment trouver le mode dans un histogramme en utilisant python et matplotlib
import numpy as np
import matplotlib.pyplot as plt
data = np.random.randn(100000) * 2.0 + 10.0
hx, hy, _ = plt.hist(data, bins=50, normed=1,color="lightblue")
bin_max = np.where(hx == hx.max())[0]
print 'Mode hauteur', max(hx)
print 'Mode position', ( hy[bin_max] + hy[bin_max+1] ) / 2.0
plt.ylim(0.0,max(hx)+0.05)
plt.title('Find the histogram mode \n (python & matplotlib) ')
plt.grid()
plt.savefig("histogram_mode.png", bbox_inches='tight')
plt.show()
plt.close()
donne par exemple:
Mode hauteur 0.195753579984
Mode position 10.03309705
Références
Liens | Site |
---|---|
Mode (statistiques) | wikipedia |
obtain the max y-value of a histogram | stackoverflow |
Find the x value corresponding to a histogram max | stackoverflow |