Skip to content
color_scale

color_scale

Mojo module 🡭

color_scale

ColorScale maps a continuous data domain onto a color gradient, for data-driven color encoding (Plot.encode(color=...)). Stop interpolation is shared with canvas.gradient’s LinearGradient/ RadialGradient through its GradientStops, which became public in canvas_mojo v0.18.0 (the same code was reached through _color_at_t/ _GradientStop/_insert_stop before). Only the projection differs: those project a pixel position onto the unit interval; this projects a data value, the way LinearScale does for position.

Normalization – which data values the ramp spans, and where its middle color lands – is kept separate from that interpolation. _ColorDomainOverride carries the caller’s answer from Plot.scale_color_domain()/Plot.scale_color_center() down to the marks, _color_scale_for() is the one place every mark turns it into a ColorScale, and shared_color_domain() computes one domain over several charts’ data so they can be compared (the color counterpart to shared_bin_edges()).

Structs

  • ColorScale: A linear color gradient from domain_min to domain_max. There is no pixel range as in LinearScale; color_at(value) is the whole interface. A zero-span domain projects every value to t=0.0, the lowest-offset stop’s color.

Functions