【发布时间】:2016-08-02 12:56:53
【问题描述】:
我正在尝试使用这些值创建直方图:
[1, 1, 1, 2, 2, 1, 1, 1, 1, 5, 2, 1, 1, 2, 2, 1, 1, 4, 1, 1, 2, 1, 1, 2]
我使用的代码是这样的
plt.hist(values, histtype='bar', color='green', alpha=0.5)
plt.title(library_name, fontsize=12)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
x1, x2, y1, y2 = plt.axis()
plt.axis((x1-0.5, x2+0.5, y1, y2+0.05))
plt.savefig("../results/histograms/" + library_name)
有谁知道为什么第一个和最后一个小节看起来除了 xtick 之外?我尝试使用 plt.margins 函数但没有结果。
非常感谢
【问题讨论】:
-
matplotlib 分箱是非常自动的,并且对您的意图毫不在意。默认情况下,它会在最小值和最大值之间创建 10 个 bin。因此,在许多情况下,您必须手动指定垃圾箱(如 Samuel Bancroft 的回答)
标签: python matplotlib histogram