Quantize scales¶
- detroit.scale_quantize() ScaleQuantize[T]¶
- detroit.scale_quantize(range_vals: list[T]) ScaleQuantize[T]
- detroit.scale_quantize(domain: list[int | float], range_vals: list[T]) ScaleQuantize[T]
Builds a new quantize 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:
Examples
>>> scale = d3.scale_quantize([0, 100], d3.SCHEME_BLUES[6]) >>> for x in range(11): ... x = 10 * x ... print(x, scale(x)) ... ... 0 #f7fbff 10 #f7fbff 20 #deebf7 30 #c6dbef 40 #9ecae1 50 #6baed6 60 #4292c6 70 #2171b5 80 #08519c 90 #08306b 100 #08306b
- class detroit.scale.quantize.ScaleQuantize¶
- __call__(x: int | float | None = None) T¶
Given a value in the input domain, returns the corresponding value in the output range.
- Parameters:
x (Number | None) – 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 quantize. This method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse.
- Parameters:
y (T) – Input value
- Returns:
Output value
- Return type:
Number
- set_domain(domain: list[int | float]) ScaleQuantize¶
Sets the scale’s domain to the specified two-element array of numbers.
- Parameters:
domain (list[Number]) – Domain
- Returns:
Itself
- Return type:
- set_range(range_vals: list[T]) ScaleQuantize¶
Sets the scale’s range to the specified array of values
- Parameters:
range_vals (list[T]) – Range values
- Returns:
Itself
- Return type:
- set_unknown(unknown: Any) ScaleQuantize¶
Sets the scale’s unknown value
- Parameters:
unknown (Any) – Unknown value
- Returns:
Itself
- Return type:
- ticks(count: int | None = None) list[int | float]¶
Returns approximately count representative values from the scale’s domain.
- Parameters:
count (int | None) – Count. If specified, the scale may return more or fewer values depending on the domain
- Returns:
Tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10), and are guaranteed to be within the extent of the domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data.
- Return type:
list[Number]
- tick_format(count: int | None = None, specifier: str | None = None) Callable[[int | float], str]¶
Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values. The specified count should have the same value as the count that is used to generate the tick values.
- Parameters:
count (int | None) – Count. It should have the same value as the count that is used to generate the tick values.
specifier (str | None) – Specifier
- Returns:
Tick format function
- Return type:
Callable[[Number], str]
- nice(count: int | None = None) LinearBase¶
Extends the domain so that it starts and ends on nice round values.
- Parameters:
count (int | None) – Count argument allows greater control over the step size used to extend the bounds, guaranteeing that the returned ticks will exactly cover the domain
- Returns:
Itself
- Return type: