[Numpy-discussion] help creating a reversed cumulative histogram

josef.pktd@gmai... josef.pktd@gmai...
Wed Sep 2 18:55:03 CDT 2009


On Wed, Sep 2, 2009 at 7:26 PM, Robert Kern<robert.kern@gmail.com> wrote:
> On Wed, Sep 2, 2009 at 18:15, Tim Michelsen<timmichelsen@gmx-topmail.de> wrote:
>> 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.
>
> Okay. That is completely different from what you've asked before.
>
>> 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.
>
>> 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]
>
> This is not the kind of "inversion" that you are looking for. You want
>
> ecdf_inv_sums = ecdf_sums[-1] - ecdf_sums

and you can plot the histogram with bar

eisf_sums = ecdf_sums[-1] - ecdf_sums   # empirical inverse survival
function of weights
width = sums[1][1] - sums[1][0]
rects1 = plt.bar(sums[1], eisf_sums, width, color='b')

Are you sure you want cumulative weights in the histogram?

Josef

>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
>  -- Umberto Eco
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list