how to generate heat maps given the points

前端 未结 8 1706
猫巷女王i
猫巷女王i 2021-02-06 07:59

I want to generate a heat map in windows form. I have a set of points as the input. How to go about doing this in the simplest way? Thanks.

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 08:57

    This worked well for me.

    public Color HeatMap(float value, float max)
        {
            int r, g, b;
            float val = value / max; // Assuming that range starts from 0
            if (val > 1)
                val = 1;
            if (val > 0.5f)
            {
                val = (val - 0.5f) * 2;
                r = Convert.ToByte(255 * val);
                g = Convert.ToByte(255 * (1 - val));
                b = 0;
            }
            else
            {
                val = val * 2;
                r = 0;
                g = Convert.ToByte(255 * val);
                b = Convert.ToByte(255 * (1 - val));
            }
            return Color.FromArgb(255, r, g, b);
        }
    

提交回复
热议问题