Calculate RGB value for a range of values to create heat map

前端 未结 4 1770
故里飘歌
故里飘歌 2020-12-04 13:01

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

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 13:21

    "We sense light intensity on a logarithmic scale – an exponential intensity ramp will be seen as a linear ramp" https://courses.cs.washington.edu/courses/cse455/09wi/Lects/lect11.pdf

    From the https://en.wikipedia.org/wiki/RGB_color_model: "an input intensity RGB value of (0.5, 0.5, 0.5) only outputs about 22% of full brightness (1.0, 1.0, 1.0), instead of 50%"

    This leads to the brownish smudge at 2.5 in @martineau example, where it should be yellow, and cyan at 1.5 in order to get a proper hue gradient.

    So the formula you should use to get the gradient is not necessarily what you will want. (sorry for not answering your question directly)

    But it might be handy to convert to the HSV or HLS color space model, and use H (for hue) and use that as input, and convert back to RGB for display purposes. ie:

    colorsys.hsv_to_rgb(value, 1, 1)
    

    https://docs.python.org/2/library/colorsys.html

提交回复
热议问题