I am trying to create a heat map with python. For this I have to assign an RGB value to every value in the range of possible values. I thought of changing the color from blu
You can often eliminate an if with an index into an array of two values. Python lacks a ternary conditional operator, but this works:
r = [red_curve_1, red_curve_2][value>=halfmax]
g = [green_curve_1, green_curve_2][value>=halfmax]
b = [blue_curve_1, blue_curve_2][value>=halfmax]
Replace the *_curve_1 and *_curve_2 expressions with the constants or slopes or curves either left or right of the midpoint, respectively.
I'll leave those substitutions to you, but for example:
red_curve_1 and blue_curve_2 are simply 0green_curve_1 is 255*(value-minimum)/(halfmax-minimum)