2017-05-10 114 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

相關問題