Log scales

detroit.scale_log() ScaleLog
detroit.scale_log(range_vals: list[int | float]) ScaleLog
detroit.scale_log(domain: list[int | float], range_vals: list[int | float]) ScaleLog

Builds a new log scale with the specified domain and range, the base 10, the default interpolator and clamping disabled.

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

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

Returns:

Scale object

Return type:

ScaleLog

Examples

>>> scale = d3.scale_log([1, 10], [0, 960])
>>> steps = 10
>>> for x in range(steps + 1):
...     x = x / steps
...     x = 10 ** x
...     print(x, scale(x))
...
...
1.0 0.0
1.2589254117941673 96.0
1.5848931924611136 192.0
1.9952623149688795 287.99999999999994
2.51188643150958 383.99999999999994
3.1622776601683795 480.0
3.9810717055349722 576.0
5.011872336272722 671.9999999999999
6.309573444801933 767.9999999999999
7.943282347242816 864.0
10.0 960.0
class detroit.scale.log.ScaleLog

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 \log(x) + b\).

__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[float]) ScaleLog

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

Parameters:

domain (list[float]) – Domain

Returns:

Itself

Return type:

ScaleLog

set_range(range_vals)

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:

Transformer

set_base(base: int | float) LogBase

Sets the scale’s base value

Parameters:

base (Number) – Base value

Returns:

Itself

Return type:

LogBase

set_clamp(clamp: bool) Transformer

Enables or disables clamping.

Parameters:

clamp (bool) – Clamp value

Returns:

Itself

Return type:

Transformer

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:

Transformer

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:

LogBase

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:

LogBase

nice() LogBase

Like ScaleLinear.nice, except extends the domain to integer powers of base.

Returns:

Itself

Return type:

LogBase