Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8689433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:38:43+00:00 2026-06-12T23:38:43+00:00

Assuming values are normalized from 0 to 1, what is the algoritm to get

  • 0

Assuming values are normalized from 0 to 1, what is the algoritm to get a color to create a heatmap like this?

1 is red, .5 is green, 0 is dark blue.

Working in RMagick / ImageMagick.

heatmap

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:38:45+00:00Added an answer on June 12, 2026 at 11:38 pm

    I found this surprisingly easy to do with HSL.

    In Ruby:

    def heatmap_color_for value # [0,1]
      h = (1 - value) * 100
      s = 100
      l = value * 50
      "hsl(#{h.round(2)}%,#{s.round(2)}%,#{l.round(2)}%)"
    end
    

    This method returns HSL values as a string between 0% and 100%. It can be used with RMagick or ImageMagick.

    Reference: ImageMagick HSL documentation.

    In Java, for CSS, tested:

    private String getHeatmapColorForCSS(double normalizedValue0to1) {
        double h = (1 - normalizedValue0to1) * 360;
        double s = 100;
        double l = 50;
        return String.format("hsl(%.2f, %.2f%%, %.2f%%)", h, s, l);
    }
    

    Note the key difference between CSS and ImageMagick: the first value is 0-360 and without a percent sign.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming that I have a basic enum like: public enum Color { Red, Green,
Assuming this is how you get the current time in Joda time : DateTime
assuming i had RGBA (32 bits) output from frame-grabber, with alpha channel unused (values
Assuming a normal JFrame, I'm trying to get the inset values before the frame
Assuming I have an SQL table with this schema: CREATE TABLE( foo INTEGER, bar
Assuming a tab-separated values (TSV) file with a header line, how would one create
Assuming that I have this: enum { A = 0x2E, B = 0x23, C
Assuming: std::string ToShow,NumStr; The following displays This is 19 ch00: ToShow = This is
Okay, I'm trying to use this method to get my data into R, but
Assuming CREATE TABLE TableA ( IntColumn INT NOT NULL PRIMARY KEY ) INSERT INTO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.