2017-05-10 14 views
0

私はPythonのディスプレイに同じビン幅は

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

私の問題は、彼らが、図に表示されるビン幅が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

関連する問題