How does the math behind heat map filters work?
About your question concerning ColorMaps: 
A cv2 ColorMap is basically just a lookup table which directly maps the intensity values of the input image to a predefined RGB color. In its essences it is exactly what you did by categorizing and associating with a specific color value.

Most of the cv2 ColorMaps just have a little more detail, most of them have either 64( "Rainbow", "Hot", ...) or 256 ("Jet", "Magma", ...) steps, some like "Winter" have 11. They come from the GNU Octave or Matlab color palettes.

If you really want to build this lookup table yourself the easiest way to achieve a high level of granularity for the individual steps is to use the HSV color space   

import numpy as np
import cv2

N_STEPS = 20
h = np.linspace(0, 180, N_STEPS, endpoint=False) # cv2 Hue range is [0, 179]  
s = np.ones_like(h)*255   # cv2 saturation range is from [0, 255]; adjust it to your liking
v = np.ones_like(h)*255   # cv2 value range is from [0, 255]; adjust it to your liking
hsv_colormap = np.dstack([h,s,v])

rgb_colormap = cv2.cvtColor(np.uint8(hsv_colormap), cv2.COLOR_HSV2RGB)

IMG_SIZE = 100
#intensities = np.random.random((IMG_SIZE,IMG_SIZE)) # from 0 to 1
intensities = np.array([np.linspace(0,1, IMG_SIZE, endpoint=False), ]*IMG_SIZE) # from 0 to 1
intensity_indices = np.uint8(N_STEPS*intensities) # map insity ranges to discretized intervals 

color_mapped_intensities = rgb_colormap[0,intensity_indices,:] 
cv2.imshow('colormap', color_mapped_intensities)

cv2.waitKey(0)


you can play around with the Hue values ranges to feed into the color map

Happy color mapping to you !