如何绘制彩票号码的直方图?

how to plot histogram of lottery numbers?

我正在使用 ipython 笔记本来绘制彩票号码结果的直方图。我想演示每个数字出现了多少次。我在像矩阵这样的 CSV 文件中绘制结果。我试图在 numpy 矩阵中加载数字,然后将其转换为 int 数组,然后使用 matplotlib.pyplot.hist() 绘制它 - 但我得到了错误的结果(看起来像错误的 bin,只显示了 5 个矩形,但我看不到范围)。最简单的方法是什么?

如果不指定bin的范围和数量,matplotlib.pyplot.hist()会猜猜范围,默认为10个bin。这通常不是您想要的。

以下按预期工作

import matplotlib.pyplot as plt
from numpy import random
N = random.random_integers( 0, 10, 20 )
plt.hist( N, range=[-.5,10.5], bins=11 )
plt.show()

我确实将范围移动了 0.5,这样条形图就可以很好地与刻度线对齐。