I have a function that returns float results in the interval [0.0, 1.0]. I would like to visualize the results using color ranging from red for 0.0 to green for 1.0 (maybe through yellow for 0.5). How could I do that? Thanks!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think the simplest way is to work in HSL/HSB (hue saturation lightness), where the hue values 0-33% of the maximum will map to the range red-orange-yellow-green. The advantage of working is HSL (vs RGB) is that the resulting color range will be much better-looking (eg bright yellow in RGB contains a pinch of blue).
So basically you will create a value based on a constant S and L value, and a H that corresponds to
and then transform that value back to RGB for display. Don’t know Python (shame on me) but apparently the colorsys module can do this transformation for you.