Skip to content

ColorScale

The ColorScale class creates a color scale that maps a numeric value from a given domain to an interpolated hex color between two specified colors.

pydreamplet.scales.ColorScale

ColorScale(
    domain: tuple[float, float],
    output_range: tuple[str, str]
)

Parameters

  • domain (tuple[float, float]): The numeric input domain.
  • output_range (tuple[str, str]): A tuple of two hex color strings representing the start and end colors.
color_scale = ColorScale((0, 100), ("#ff0000", "#00ff00"))
print(color_scale.map(50))  # Outputs an #7f7f00

map

map(value: float) -> str

Maps the input numeric value to an interpolated hex color.

domain

Get or set the numeric domain.

output_range

Get or set the pair of hex colors.