[Numpy-discussion] help creating a reversed cumulative histogram

Tim Michelsen timmichelsen@gmx-topmail...
Wed Sep 2 18:15:28 CDT 2009


Hello fellow numy users,
I posted some questions on histograms recently [1, 2] but still couldn't 
find  a solution.

I am trying to create a inverse cumulative histogram [3] which shall 
look like [4] but with the higher values at the left.

The classification shall follow this exemplary rule:

class 1: 0
all values > 0

class 2: 10
all values > 10

class 3: 15
all values > 15

class 4: 20
all values > 20

class 5: 25
all values > 25

[...]

I could get this easily in a spreadsheet by creating a matix with 
conditional statements (if VALUES_COL > CLASS_BOUNDARY; VALUES_COL; '-').

With python (numpy or pylab) I was not successful. The plotted histogram 
envelope turned out to be just the inverted curve as the one created 
with the spreadsheet app.
	
I have briely visualised the issue here [5]. I hope that this makes it 
more understandable.
	
Later I would like to sum and count all values in each bin as discussed 
in [2].

May someone give me pointer or hint on how to improve my code below to 
achive the desired histogram?



Thanks a lot in advance,
Timmie

[1]: http://www.nabble.com/np.hist-with-masked-values-to25243905.html
[2]: 
http://www.nabble.com/histogram%3A-sum-up-values-in-each-bin-to25171265.html
[3]: http://en.wikipedia.org/wiki/Histogram#Cumulative_histogram
[4]: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=126
[5]: http://www.scribd.com/doc/19371606/Distribution-Histogram

##### CODE #####
normed = False
values # loaded data as array
bins = 10


### sum
## taken from
## 
http://www.nabble.com/Scipy-and-statistics%3A-probability-density-function-to24683007.html#a24683304
sums = np.histogram(values, weights=values,
                                     normed=normed,
                                     bins=bins)
ecdf_sums = np.hstack([0.0, sums[0].cumsum() ])
ecdf_inv_sums = ecdf_sums[::-1]


pylab.plot(sums[1], ecdf_inv_sums)
pylab.show()



More information about the NumPy-Discussion mailing list