<p>这里的问题是垃圾箱。你知道吗</p>
<p>您希望避免将任何两个(或更多)值组合在一起,否则密度将是1/6的倍数。你知道吗</p>
<p>下面是如何正确设置垃圾箱:</p>
<pre><code>fair = np.array([1, 2, 3, 4, 5, 6]*100)
plt.hist(fair, density=True, bins=[1,2,3,4,5,6,7], label='Fair Die', rwidth=0.9, align='left') # rwidth is optional
plt.show()
</code></pre>
<p>从<a href="https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html" rel="nofollow noreferrer">the docs</a>:</p>
<blockquote>
<p>bins : array</p>
<p>The edges of the bins. Length nbins + 1 (nbins left edges and right edge of last bin). Always a single array even when multiple data sets are passed in.</p>
</blockquote>
<p>注意:如果希望显示标签,请在<code>plt.show()</code>之前调用<code>plt.legend()</code>。你知道吗</p>
<p>注2:在这种情况下,建议设置<code>rwidth</code><;binsize,否则在bins之间没有空间,这里所有的bis都具有相同的维度,因此都显示为单个块。<strong>看看评论,看看这是如何让人困惑的:P<strong></p>
<p>或者,您可以在条形图周围绘制边框:</p>
<pre><code>plt.hist(fair, density=True, bins=range(1,8), label='Fair Die', edgecolor='white', linewidth=1.2)
</code></pre>
<p><a href="https://i.stack.imgur.com/h7L8G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h7L8G.png" alt="enter image description here"/></a></p>
<p><strong>奖金:</strong></p>
<p>如果您想拥有<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.random_integers.html" rel="nofollow noreferrer">stochastic representation of your fair dice</a>:</p>
<pre><code>fair_proba = np.random.random_integers(1,6, 1000)
</code></pre>
<p><a href="https://i.stack.imgur.com/pIy3w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pIy3w.png" alt="enter image description here"/></a></p>