Turbo colormap (rainbow colormap)

By | 3月 30, 2026

Turbo, An Improved Rainbow Colormap for Visualization. – Google 工程师定义的

这种颜色非常适合用品渲染 深度图 例如 heatmap.

它的颜色定义 (python 版本)

// [R, G, B] * 256
turbo_colormap_data = [[0.18995,0.07176,0.23217],[0.19483,0.08339,0.26149], ...]

R, G, B 的值 = 颜色数值 / 255。所以将其转换成16进制的颜色用下面的方法.

function floatColorToHexRGBA(color: number[]): string {
  const r = Math.round(color[0] * 255);
  const g = Math.round(color[1] * 255);
  const b = Math.round(color[2] * 255);

  return (
    "#" +
    r.toString(16).padStart(2, "0") +
    g.toString(16).padStart(2, "0") +
    b.toString(16).padStart(2, "0")
  );
}

有人定义了 typescript 版本的 turbo-colormap,里面除了定义颜色,还有很多颜色处理的函数。