So I had a similar problem when I wanted to set up normal normalization in that the regular percentile of the zero point or z-score was insufficient. Sometimes I knew what the possible max and minimum numbers of the population were, and therefore I wanted to define it, except for my sample, or another middle, or something else! Therefore, I created a custom function (additional steps in the code were used here to make it as readable as possible):
def NormData(s,low='min',center='mid',hi='max',insideout=False,shrinkfactor=0.): if low=='min': low=min(s) elif low=='abs': low=max(abs(min(s)),abs(max(s)))*-1.#sign(min(s)) if hi=='max': hi=max(s) elif hi=='abs': hi=max(abs(min(s)),abs(max(s)))*1.#sign(max(s)) if center=='mid': center=(max(s)+min(s))/2 elif center=='avg': center=mean(s) elif center=='median': center=median(s) s2=[x-center for x in s] hi=hi-center low=low-center center=0. r=[] for x in s2: if x<low: r.append(0.) elif x>hi: r.append(1.) else: if x>=center: r.append((x-center)/(hi-center)*0.5+0.5) else: r.append((x-low)/(center-low)*0.5+0.) if insideout==True: ir=[(1.-abs(z-0.5)*2.) for z in r] r=ir rr =[x-(x-0.5)*shrinkfactor for x in r] return rr
It takes a series of pandas or even just a list and normalizes it to your low, central and high points. there is also a compression ratio! so that you can scale the data away from 0 and 1 (I had to do this when combining color codes in matplotlib: A single pcolormesh with more than one color scheme using Matplotlib ) So you can see how the code works, but basically they say that you have the values ββ[-5,1,10] in the sample, but you want to normalize based on the range from -7 to 7 (so nothing higher than 7, our "10" is effectively treated as 7) with a middle of 2, but reduces it up to 256 RGB colors:
#In[1] NormData([-5,2,10],low=-7,center=1,hi=7,shrinkfactor=2./256)
It can also turn your data inside out ... it may seem strange, but I found it useful for thermal material. Suppose you want a darker color for values ββclose to 0, not hi / low. You can heat the map based on normalized data, where inout = True:
#In[2] NormData([-5,2,10],low=-7,center=1,hi=7,insideout=True,shrinkfactor=2./256)
So, now β2β, which is closest to the center, defined as β1β, is the highest value.
In any case, I thought that my question is very similar to yours, and this function may be useful to you.