Threshold scales¶
- detroit.scale_threshold() ScaleThreshold[T]¶
- detroit.scale_threshold(range_vals: list[T]) ScaleThreshold[T]
- detroit.scale_threshold(domain: list[int | float], range_vals: list[T]) ScaleThreshold[T]
Builds a new threshold scale with the specified domain and range.
- Parameters:
domain (list[int | float]) – Array of numbers
range_vals (list[int | float]) – Array of values
- Returns:
Scale object
- Return type:
Examples
>>> scale = d3.scale_threshold([0, 1], ["red", "white", "blue"]) >>> for x in range(steps + 1): ... x = -1 + 2 * x / steps ... print(x, scale(x)) ... ... -1.0 red -0.8 red -0.6 red -0.4 red -0.19999999999999996 red 0.0 white 0.19999999999999996 white 0.3999999999999999 white 0.6000000000000001 white 0.8 white 1.0 blue
- class detroit.scale.threshold.ScaleThreshold¶
Threshold scales are similar to quantize scales, except they allow you to map arbitrary subsets of the domain to discrete values in the range. The input domain is still continuous, and divided into slices based on a set of threshold values. See this choropleth for an example.
- __call__(x: int | float | None = None) T¶
Given a value in the input domain, returns the corresponding value in the output range.
- Parameters:
x (int | float | None) – Input value
- Returns:
Output value
- Return type:
T
- invert_extent(y: T) list[int | float | None]¶
Returns the extent of values in the domain \([x_0, x_1]\) for the corresponding value in the range, representing the inverse mapping from range to domain.
- Parameters:
y (T) – Input value
- Returns:
\([x_0, x_1]\) values
- Return type:
list[int | float | None]
- set_domain(domain: list[int | float]) ScaleThreshold¶
Sets the scale’s domain to the specified array of values.
- Parameters:
domain (list[int | float]) – Domain
- Returns:
Itself
- Return type:
- set_range(range_vals: list[T]) ScaleThreshold¶
Sets the scale’s range to the specified array of values.
- Parameters:
range_vals (list[T]) – Range
- Returns:
Itself
- Return type:
- set_unknown(unknown: Any) ScaleThreshold¶
Sets the scale’s unknown value.
- Parameters:
unknown (Any) – Unknown value
- Returns:
Itself
- Return type: