0
bins = [0,1,10,20,30,40,50,75,100]
plt.figure(figsize=(15,15))
plt.hist(df.v1, bins = bins)
我的问题是因为它们出现在图中的bin宽度正比于它们在bins
范围。不过,我希望所有箱子都具有相同的宽度。
bins = [0,1,10,20,30,40,50,75,100]
plt.figure(figsize=(15,15))
plt.hist(df.v1, bins = bins)
我的问题是因为它们出现在图中的bin宽度正比于它们在bins
范围。不过,我希望所有箱子都具有相同的宽度。
我不知道如何理解结果,但可以使用numpy.histogram
来计算条形的高度,然后将这些直接绘制到任意的x轴上。
x = np.random.normal(loc=50, scale=200, size=(2000,))
bins = [0,1,10,20,30,40,50,75,100]
fig = plt.figure()
ax = fig.add_subplot(211)
ax.hist(x, bins=bins, edgecolor='k')
ax = fig.add_subplot(212)
h,e = np.histogram(x, bins=bins)
ax.bar(range(len(bins)-1),h, width=1, edgecolor='k')