擅长:python、mysql、java
<p>这个问题是<a href="https://stackoverflow.com/questions/37649342/matplotlib-how-to-make-a-histogram-with-bins-of-equal-area/37667480">similar to one</a>我刚才写了一个答案,但完全不同,足以证明它是自己的问题。结果发现,这个解决方案使用的代码与我的另一个答案基本相同。</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>这个解决方案给出了一个具有相等高度的像素点的直方图,因为根据定义,直方图是每个像素点的个数。</p>
<p>要获得pdf(即密度函数),请使用<code>normed=True</code>kwarg To plt.hist。如我的<a href="https://stackoverflow.com/questions/37649342/matplotlib-how-to-make-a-histogram-with-bins-of-equal-area/37667480">other answer</a>所述。</p>