我試圖運行下面的代碼:疊加柱狀圖不會疊加
variable_values = #numpy vector, one dimension, 5053 values between 1 and 0.
label_values = #numpy vector, one dimension, 5053 values, discrete value of either 1 OR 0.
x = variable_values[variable_values != '?'].astype(float)
y = label_values[variable_values != '?'].astype(float)
print np.max(x) #prints 0.90101
print np.max(y) #prints 1.0
N = 5053
ind = np.arange(N) # the x locations for the groups
width = 0.45 # the width of the bars: can also be len(x) sequence
n, bins, patches = plt.hist(x, 5, stacked=True, normed = True)
#Stack the data
plt.figure()
plt.hist(x, bins, stacked=True, normed = True)
plt.hist(y, bins, stacked=True, normed = True)
plt.show()
我想實現如下圖:
隨着各條分割的顏色根據其是否爲label
的值爲1或0.
不幸的是我的輸出當前是:
有兩件事情不正確使用此 - 它不是堆疊適當首先的。其次,Y軸上的值上升到1.6,但我相信Y軸應該包含落入每個子組的數據數量(因此,如果所有數據段的值都是0-0.25,將顯示數據的酒吧將是第一個)。
這是一個直方圖..最高峯將是最頻繁的價值,而不是最大的價值。 – M4rtini
@ M4rtini對不起,是的,你說得對 - 這是爲什麼在這裏打印出最大值1.6?理想情況下,Id喜歡將5053條數據拆分爲四個條(Y軸上顯示數據的數量),並將條分割爲數字,其中標籤== 1和標籤== 0。道歉,我對自己的問題感到困惑。現在會更新。 –