how to generate heat maps given the points

前端 未结 8 1828
猫巷女王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条回答
  •  我寻月下人不归
    2021-02-06 08:46

    Building on the answers already here, this method allows you to specify the Colors you wish to use as the max and min colours.

    private Color HeatMapColor(double value, double min, double max)
    {
        Color firstColour = Color.RoyalBlue;
        Color secondColour = Color.LightSkyBlue;
    
        // Example: Take the RGB
        //135-206-250 // Light Sky Blue
        // 65-105-225 // Royal Blue
        // 70-101-25 // Delta
    
        int rOffset = Math.Max(firstColour.R, secondColour.R);
        int gOffset = Math.Max(firstColour.G, secondColour.G);
        int bOffset = Math.Max(firstColour.B, secondColour.B);
    
        int deltaR = Math.Abs(firstColour.R - secondColour.R);
        int deltaG = Math.Abs(firstColour.G - secondColour.G);
        int deltaB = Math.Abs(firstColour.B - secondColour.B);
    
        double val = (value - min) / (max - min);
        int r = rOffset - Convert.ToByte(deltaR * (1 - val));
        int g = gOffset - Convert.ToByte(deltaG * (1 - val));
        int b = bOffset - Convert.ToByte(deltaB * (1 - val));        
    
        return Color.FromArgb(255, r, g, b);
    }
    

    The results look like this for a test DataGrid with some sample data.

    enter image description here

提交回复
热议问题