Histogram with equal number of points in each bin
<p>I have a sorted vector <code>points</code> with 100 points. I now want to create two histograms: the first histogram should have 10 bins having equal width. The second should also have 10 histograms, but not necessarily of equal width. In the second, I just want the histogram to have the same number of points in each bin. So for example, the first bar might be very short and wide, while the second bar in the histogram might be very tall and narrow. I have code that creates the first histogram using <code>matplotlib</code>, but now I'm not sure how to go about creating the second one.</p>

<pre><code>import matplotlib.pyplot as plt
points = [1,2,3,4,5,6, ..., 99]
n, bins, patches = plt.hist(points, 10)
</code></pre>

<p><strong>Edit:</strong></p>

<p>Trying the solution below, I'm a bit puzzled as to why the heights of all of the bars in my histogram are the same.</p>

<p><a href="http://i.stack.imgur.com/Sr9tk.png" rel="nofollow"><img src="http://i.stack.imgur.com/Sr9tk.png" alt="enter image description here"></a></p>

<p>This question is <a href="http://stackoverflow.com/questions/37649342/matplotlib-how-to-make-a-histogram-with-bins-of-equal-area/37667480">similar to one</a> that I wrote an answer to a while back, but sufficiently different to warrant it's own question. The solution, it turns out, uses basically the same code from my other answer.</p>

<pre><code>def histedges_equalN(x, nbin):
    npt = len(x)
    return np.interp(np.linspace(0, npt, nbin + 1),
                     np.arange(npt),
                     np.sort(x))

x = np.random.randn(100)
n, bins, patches = plt.hist(x, histedges_equalN(x, 10))
</code></pre>

<p>This solution gives a histogram with equal height bins, because---by definition---a histogram is a count of the number of points in each bin.</p>

<p>To get a pdf (i.e. density function) use the <code>normed=True</code> kwarg to plt.hist. As described in my <a href="http://stackoverflow.com/questions/37649342/matplotlib-how-to-make-a-histogram-with-bins-of-equal-area/37667480">other answer</a>. </p>

python matplotlib histogram