Discretized Color Scales

Cars scatterplot of horsepower and fuel economy
Quantitative positions with nominal color.

Discretized point color

Quantitative point color can create concrete color classes instead of a continuous gradient:

program.encodeColor({
  field: "life_expect",
  fieldType: "quantitative",
  scale: {
    type: "threshold",
    domain: [60, 70, 75, 80],
    range: ["#440154", "#3b528b", "#21918c", "#5ec962", "#fde725"]
  }
});

An exact boundary belongs to the upper interval. reverse: true reverses the resolved colors without changing boundaries. createLegend() infers an interval legend with labels such as < 60, 60–70, and ≥ 80. These mappings are available through quantitative point encodeColor and the direct scale vocabulary. A type-changing editScale call validates the complete replacement definition before rematerializing its consumers. Explicit discretized color ranges contain at most 10,000 colors.

Quantize boundaries and interval labels remain distinct across very large, very small, and close finite values. If the numeric extent cannot represent the requested number of equal-width classes, resolution throws a RangeError instead of silently creating duplicate classes.

Scale overview · Encodings · Troubleshooting