事後的解決方案非常簡單明瞭。直方圖對象只是每個bin出現的數組,因此我只是直接使用了直方圖的cumsum。
所以基本上
import histogram, numpy
y = range(0, 100) #Except I used real data
Hist = histogram(y, bins=100, range=[0,100])
colors = ['red', 'blue', 'green', ]
ranges = [[0,30], [30,31], [31,100]]
fig = pyplot.figure(figsize=(8,6))
ax, plt, _ = fig.plothist(Hist, alpha=0) # plot for spacing
for c, r in zip(colors, ranges):
plt = ax.overlay(Hist, range=r, facecolor=c)
print y
CumulativeHist = numpy.cumsum(h6)
colors = ['red', 'blue', 'green', ]
ranges = [[0,30], [30,31], [31,100]]
fig = pyplot.figure(figsize=(8,6))
ax, plt, _ = fig.plothist(CumulativeHist, alpha=0) # plot for spacing
for c, r in zip(colors, ranges):
plt = ax.overlay(CumulativeHist, range=r, facecolor=c)
pyplot.show()
將使兩個地塊,其中第二個是第二的累積版本。 感謝您的幫助。
Alex
你有什麼試過的?向我們展示您嘗試過的方式,並且我們可以幫助您解決問題。 – tacaswell 2013-03-07 17:16:25
嗯,我試過的有點尷尬,我想「哦,我只需要輸入數據就可以了,所以我就這麼做了,我立即明白了,我不需要輸入數據,我需要將cumsum我找到了histogram.py文件,試圖找出它出現的地方,但是在任何地方都找不到它,看起來它可能是對象中的histogram.h或histogram.e,但我並不真正知道 – 2013-03-07 22:24:03
你需要提供更多的上下文當你使用這個代碼時它會給你什麼錯誤什麼是self.occurrences定義爲? – tacaswell 2013-03-07 22:32:08