2017-05-10 116 views
0

我有此代码Python的显示为不同的仓相同箱宽度尺寸

bins = [0,1,10,20,30,40,50,75,100] 
plt.figure(figsize=(15,15)) 
plt.hist(df.v1, bins = bins) 

我的问题是因为它们出现在图中的bin宽度正比于它们在bins范围。不过,我希望所有箱子都具有相同的宽度。

回答

0

我不知道如何理解结果,但可以使用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') 

enter image description here

相关问题