Avec matplotlib pour un avoir intervalle fixe pour un histogramme, il existe l'option bins (plt.hist(data, bins=bins), il suffit de lui donne un intervalle (liste ou une matrice 1d), exemple pour avoir un intervalle fixe pour deux histogrammes:

import numpy as npimport matplotlib.pyplot as pltbins = np.linspace(-5, 15, 100)data1 = np.random.randn(100000)plt.hist(data1, bins=bins, normed=1,color="lightblue")mu = 5.0sigma = 3.0data2 = np.random.randn(100000) * sigma + muplt.hist(data2, bins=bins, normed=1,color="red", alpha=0.5)plt.title('Two histograms (alpha=0.5 + same bins size)')plt.grid()plt.savefig("two_histograms_03.png", bbox_inches='tight')plt.show()
Références
| Liens | Site |
|---|---|
| Matplotlib: How to make two histograms have the same bin width? | stackoverflow |
| hist() | matplotlib doc |
| Plot two histograms at the same time with matplotlib | stackoverflow |
| pylab_examples example code: histogram_demo.py | matplotlib doc |
