Ordinal scales

detroit.scale_ordinal() ScaleOrdinal[U, V]
detroit.scale_ordinal(range_vals: list[V]) ScaleOrdinal[U, V]
detroit.scale_ordinal(domain: list[U], range_vals: list[V]) ScaleOrdinal[U, V]

Build a new ordinal scale with the specified domain and range

Parameters:
  • domain (list[U]) – Array of values

  • range_vals (list[V]) – Array of values

Returns:

Scale object

Return type:

ScaleOrdinal[U, V]

Examples

>>> scale = d3.scale_ordinal(["a", "b", "c"], ["red", "green", "blue"])
>>> for c in "abcdefgh":
...     print(c, scale(c))
...
...
a red
b green
c blue
d red
e green
f blue
g red
h green
class detroit.scale.ordinal.ScaleOrdinal

Unlike continuous scales, ordinal scales have a discrete domain and range. For example, an ordinal scale might map a set of named categories to a set of colors, or determine the horizontal positions of columns in a column chart.

__call__(d: U) V

Given a value from the domain, returns the corresponding value from the range.

Parameters:

d (U) – Input value

Returns:

Corresponding value from the range

Return type:

V

set_domain(domain: list[U]) ScaleOrdinal

Sets the scale’s domain to the specified array of values.

Parameters:

domain (list[U]) – Domain

Returns:

Itself

Return type:

ScaleOrdinal

set_range(range_vals: list[V]) ScaleOrdinal

Sets the scale’s range to the specified array of values

Parameters:

range_vals (list[V]) – Range values

Returns:

Itself

Return type:

ScaleOrdinal

set_unknown(unknown: Any) ScaleOrdinal

Sets the output value of the scale for undefined or NaN input values.

Parameters:

unknown (Any) – Unknown value

Returns:

Itself

Return type:

ScaleOrdinal