composeui.core.colorscale

Color scales: a value’s color between a low and a high, e.g. for a table’s column.

class composeui.core.colorscale.ColorScale[source]

Bases: object

A scale of colors: the color of a value between low and high, e.g. a cell’s.

colors are the stops, evenly spaced from low’s color to high’s, as #rrggbb; a value between two stops takes a color between theirs. A value below low takes low’s color, and a value above high takes high’s. None, NaN and text take none.

Without low or high, the scale needs a range from elsewhere: a table gives it its column’s, and color takes one. With middle, the first half of the stops covers low to middle, and the second half middle to high, e.g. a diverging scale’s neutral color on zero.

sequential and diverging build the usual scales. The colors are data: the same in every theme.

colors: tuple[str, ...]

the stops’ colors, as #rrggbb, from low’s to high’s

low: float | None

the value of the first color; None: the lowest value colored

high: float | None

the value of the last color; None: the highest value colored

middle: float | None

the value of the color halfway, e.g. 0; None: halfway between low and high

classmethod sequential(*, low=None, high=None)[source]

Build viridis: dark blue for low values, to yellow for high ones.

Parameters:
Return type:

ColorScale

classmethod diverging(*, middle=0.0, low=None, high=None)[source]

Build ParaView’s “Cool to Warm”: blue below middle, gray on it, red above it.

Parameters:
Return type:

ColorScale

range(low=None, high=None)[source]

Get the scale’s low and high, each taken from the arguments when it has none.

Raise ValueError when neither gives it, or for a low above the high.

Parameters:
Return type:

tuple[float, float]

position(value, *, low=None, high=None)[source]

Get where value falls on the scale, from 0 (low) to 1 (high), clamped.

low and high are the range of a scale without its own (see range). Values all equal (low == high) fall in the middle.

Parameters:
Return type:

float

color(value, *, low=None, high=None)[source]

Get the color of value, as #rrggbb; None for None, NaN or text.

low and high are the range of a scale without its own (see range).

Parameters:
Return type:

str | None

colors_of(values, *, low=None, high=None)[source]

Get the color of each value, as color does: with NumPy for an array of numbers.

Parameters:
  • values (Iterable[Any])

  • low (Optional[float])

  • high (Optional[float])

Return type:

list[Optional[str]]

table(count)[source]

Get count colors evenly spaced from the first to the last, e.g. for a lookup table.

Parameters:

count (int)

Return type:

list[str]

static ticks(low, high, count=5)[source]

Get about count round values from low to high, e.g. for a legend’s ticks.

They are a step apart, a step of 1, 2 or 5 times a power of ten.

Parameters:
Return type:

list[float]

__init__(colors, low=None, high=None, middle=None)

Method generated by attrs for class ColorScale.

Parameters:
  • colors (Iterable[str])

  • low (Optional[float])

  • high (Optional[float])

  • middle (Optional[float])

Return type:

None