@Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        double max = 0;
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                max = matrix[i][j] > max ? matrix[i][j] : max;
            }
        }
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                double value = matrix[i][j] / max;
                if (value >= 0) {
                    int rgbValue = (int) (value == 0 ? 0 : value * 200 + 55);
                    g2.setColor(new Color(rgbValue, rgbValue, rgbValue));
                } else {
                    int rgbValue = (int) (-value < 0.00001 ? 0 : -value * 128 + 55);
                    g2.setColor(new Color(rgbValue, 0, 0));
                }
                g2.fillRect(totalPaddingX + i * (size + padding), totalPaddingY + j * (size + padding), size, size);
                g2.setColor(Color.black);
                g2.draw(new Rectangle(totalPaddingX + i * (size + padding), totalPaddingY + j * (size + padding), size, size));
            }
        }
    }