Continuous base classes¶
- class detroit.scale.continuous.Transformer(t: ~collections.abc.Callable[[int | float], int | float] = <function identity>, u: ~collections.abc.Callable[[int | float], int | float] = <function identity>)¶
Continuous transformation
- Parameters:
t (Callable[[Number], Number]) – Transform function
u (Callable[[Number], Number]) – Untransform function
- __call__(x: int | float | datetime) T¶
Given a value from the domain, returns the corresponding value from the range.
- Parameters:
x (int | float) – Input value
- Returns:
Corresponding value from the range
- Return type:
T
- invert(y: T) int | float¶
Given a value from the range, returns the corresponding value from the domain. Inversion is useful for interaction, say to determine the data value corresponding to the position of the mouse.
- Parameters:
y (T) – Input value
- Returns:
Corresponding value from the domain
- Return type:
Number
- set_domain(domain: list[int | float]) Transformer[T]¶
- set_domain(domain: list[datetime]) Transformer[T]
Sets the scale’s domain to the specified array of numbers.
- Parameters:
domain (list[Number] | list[datetime]) – Domain
- Returns:
Itself
- Return type:
Transformer[T]
- set_range(range_vals: list[int | float]) Transformer[int | float]¶
- set_range(range_vals: list[str]) Transformer[str]
- set_range(range_vals: list[datetime]) Transformer[datetime]
Sets the scale’s range to the specified array of values
- Parameters:
range_vals (list[T]) – Range values
- Returns:
Itself
- Return type:
Transformer[T]
- set_range_round(range_vals: list[T]) Transformer¶
Sets the scale’s range to the specified array of values and sets scale’s interpolator to
interpolate_round.- Parameters:
range_vals (list[T]) – Range values
- Returns:
Itself
- Return type:
- set_clamp(clamp: bool) Transformer¶
Enables or disables clamping.
- Parameters:
clamp (bool) – Clamp value
- Returns:
Itself
- Return type:
- set_interpolate(interpolate: Callable[[T, T], Callable[[float], T]]) Transformer[T]¶
Sets the scale’s range interpolator factory.
- Parameters:
interpolate (Callable[[T, T], Callable[[float], T]]) – Interpolate function
- Returns:
Itself
- Return type:
Transformer[T]
- set_unknown(unknown: Any) Transformer¶
Sets the output value of the scale for undefined or NaN input values.
- Parameters:
unknown (Any) – Unknown value
- Returns:
Itself
- Return type:
- class detroit.scale.linear.LinearBase¶
- 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:
- class detroit.scale.log.LogBase¶
Logarithmic (“log”) scales are like linear scales except that a logarithmic transform is applied to the input domain value before the output range value is computed. The mapping to the range value y can be expressed as a function of the domain value x: \(y = m \cdot \log(x) + b\).
- set_base(base: int | float) LogBase¶
Sets the scale’s base value
- Parameters:
base (Number) – Base value
- Returns:
Itself
- Return type:
- ticks(count: int | None = None) LogBase¶
Like
ScaleLinear.ticks, but customized for a log scale.- Parameters:
count (int | None) – Count. If specified, the scale may return more or fewer values depending on the domain
- Returns:
Itself
- Return type:
- tick_format(count: int | None = None, specifier: str | None = None) LogBase¶
Like
ScaleLinear.tick_format, but customized for a log scale. The specified count typically has 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:
Itself
- Return type: