擅长:python、mysql、java
<p>问题出在你的xbins上。你现在有</p>
<pre><code>xbins = [0, len(x)]
</code></pre>
<p>这会给你列表[0,100]。这意味着您将只看到1个bin(而不是2个)被0限制在0之下,而被100限制在100之上。我不完全确定你想从你的直方图中得到什么。如果你想要两个间隔不均的箱子,你可以使用</p>
<pre><code>xbins = [0, 100, 1000]
</code></pre>
<p>把100以下的东西放在一个箱子里,其他的都放在另一个箱子里。另一个选择是使用整数值来获得一定数量的均匀间隔的容器。换句话说就是</p>
<pre><code>plt.hist(x, bins=50, color='blue')
</code></pre>
<p>其中bins是所需的bin数。</p>
<p>另一方面,每当我不记得如何使用matplotlib时,我通常都会去<a href="http://matplotlib.sourceforge.net/gallery.html" rel="noreferrer">thumbnail gallery</a>找到一个例子,看起来或多或少是我想要完成的。这些示例都有附带的源代码,因此非常有用。matplotlib的<a href="http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.hist" rel="noreferrer">documentation</a>也非常方便。</p>