Search code examples
pythonnumpyscaleuniform

Scale values in uniform way?


I have an array of numbers that I convert to percentages ( values in the range [0 .. 1]). Which then I convert to gray colors.

Example :

 percentage = nums/float(nums.max())

the problem is most of the values are small numbers with couple of big numbers. This causes most of the % to be around 0.01. The result is that this translates to ~~white color which becomes invisible when plotting. BTW I have to keep all the values.

I tried to scale down the outliers abit , but even this does not help ;(

 colors[abs(colors - np.mean(colors)) > 2 * np.std(colors)] = colors.mean() + 2 * np.std(colors)
 c = colors/float(colors.max()) #convert to percentage

what this does is to scale down the outliers to 2std off the mean.

What I think I need is some sort of "step-wise" function which groups the values in such a way that they are scaled evenly in the range 0 .. 1 so that every point receives visible color, but still keeps some contrast so that the values are distinguished.

PS> May be the range has to be from 0.1 to 1 !

=====

this so far this is some sort of solution :

 c += 0.15 * (1-c) 

Solution

  • this so far this is the best solution :

    c += 0.15 * (1-c)