<p>您无法获得y轴表示列表元素值的直方图。</p>
<p>根据定义,柱状图给出了落入某个箱子中的元素数量,或在某个箱子中找到元素的概率。
<code>plt.hist</code>是从这样的直方图绘制条形图的绘图函数。</p>
<p>因此,当调用<code>plt.hist(s, normed=True, bins=5)</code>时,会发生的情况是,规范化的输入数组<code>s = [ 3, 10, 0, 7, 4]</code>被划分为0到10之间的5个容器。每个箱子里正好有一个<code>s</code>的数字,所以图中的所有条都有相同的高度。</p>
<p><a href="https://i.stack.imgur.com/ETbYa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ETbYa.png" alt="enter image description here"/></a></p>
<p>因为在这种情况下,实际上根本不需要直方图,而只需要值的条形图,所以应该使用<a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.bar" rel="nofollow noreferrer">^{<cd5>}</a>和数组<code>s</code>作为高度参数,使用一些索引作为位置。</p>
<pre><code>from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
a = ["some file", "22", "43", "11","34", "26"]
r = list(map(int, (a[1], a[2], a[3], a[4], a[5])))
s = np.array([int((x - min(r))/(max(r) - min(r)) * 10) for x in r])
plt.bar(np.arange(len(s)), s)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/WY4oi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WY4oi.png" alt="enter image description here"/></a></p>