Skip to content

Instantly share code, notes, and snippets.

@hanneshapke
Last active April 16, 2018 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanneshapke/cd2670f2264d68023b0f6882a90a0f76 to your computer and use it in GitHub Desktop.
Save hanneshapke/cd2670f2264d68023b0f6882a90a0f76 to your computer and use it in GitHub Desktop.
Generate text color depending on the heat-map value
def color(hvalue, threshold, max=1, cdefault='black', colors=['red', 'yellow', 'green', 'cyan', 'blue']):
num_colors = len(colors)
if hvalue < threshold:
return cdefault
for i, color in enumerate(colors):
if hvalue > (max - (max - threshold) / num_colors * (i + 1)):
return color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment