Quantile scales

detroit.scale_quantile() ScaleQuantile[T]
detroit.scale_quantile(range_vals: list[T]) ScaleQuantile[T]
detroit.scale_quantile(domain: list[int | float], range_vals: list[T]) ScaleQuantile[T]

Builds a new quantile scale with the specified domain and range.

Parameters:
  • domain (list[Number]) – Array of numbers

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

Returns:

Scale object

Return type:

ScaleQuantile[T]

Examples

>>> scale = d3.scale_quantile().set_domain([3, 6, 7, 8, 8, 10, 13, 15, 16, 20])
>>> scale = scale.set_range([0, 1, 2, 3])
>>> for x in range(21):
...     print(x, scale(x))
...
...
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 1
9 2
10 2
11 2
12 2
13 2
14 2
15 3
16 3
17 3
18 3
19 3
20 3
class detroit.scale.quantile.ScaleQuantile

Quantile scales map a sampled input domain to a discrete range. The domain is considered continuous and thus the scale will accept any reasonable input value; however, the domain is specified as a discrete set of sample values. The number of values in (the cardinality of) the output range determines the number of quantiles that will be computed from the domain. To compute the quantiles, the domain is sorted, and treated as a population of discrete values; see quantile.

__call__(x: int | float) T

Given a value in the input domain, returns the corresponding value in the output range.

Parameters:

x (Number) – Input value

Returns:

Output value

Return type:

T

invert_extent(y: T) int | float

Returns the extent of values in the domain \([x_0, x_1]\) for the corresponding value in the range: the inverse of quantile.

Parameters:

y (T) – Input value

Returns:

Output value

Return type:

Number

set_domain(domain: list[int | float]) ScaleQuantile

Sets the domain of the quantile scale to the specified set of discrete numeric values .

Parameters:

domain (list[Number]) – Domain

Returns:

Itself

Return type:

ScaleQuantile

set_range(range_vals: list[T]) ScaleQuantile

Sets the discrete values in the range.

Parameters:

range_vals (list[T]) – Range values

Returns:

Itself

Return type:

ScaleQuantile

set_unknown(unknown: Any) ScaleQuantile

Sets the scale’s unknown value.

Parameters:

unknown (Any) – Unknown value

Returns:

Itself

Return type:

ScaleQuantile