'Assign color to value (reupload)

I know that this question was answered a couple years ago. but the code didn't seem to work. Does anyone know a solution to this? I will attach an image of it not functioning...

I'd like to assign to values colors, using matplotlib or colormap. More concretely: If I've got a small value (let's say that -14 is the smallest value) and a high value (let's say 86 is the highest value), I'd like to print the objects with low values more red, and objects which have higher values greener (-14 --> completely red ; 86 --> completely green). For objects with values between -14 and 86, I'd like to assign to them colors between red and green.

I know there is a colormap called "RdYlGr", which goes from red-yellow-green. Maybe it's possible to use this map? But how?

In summary: how can I use maplotlib's colormaps to map a floating point number (eg, 6.2 from the range -14 to 86) to a corresponding hex color string (eg, "#A0CBE2").

this is using the old code that does not seem to work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source