Sequential scales¶
- detroit.scale_sequential() SequentialLinear¶
- detroit.scale_sequential(interpolator: Callable[[float], T]) SequentialLinear
- detroit.scale_sequential(domain: list[int | float], interpolator: Callable[[float], T]) SequentialLinear
Builds a new sequential scale with the specified domain and interpolator function or array.
- Parameters:
domain (list[Number]) – Domain
interpolator (Callable[[float], T]) – Interpolator
- Returns:
Sequential object
- Return type:
Examples
>>> scale = d3.scale_sequential([0, 100], d3.interpolate_blues) >>> for x in range(11): ... x = 10 * x ... print(x, scale(x)) ... ... 0 rgb(247, 251, 255) 10 rgb(227, 238, 249) 20 rgb(207, 225, 242) 30 rgb(181, 212, 233) 40 rgb(147, 195, 223) 50 rgb(109, 174, 213) 60 rgb(75, 151, 201) 70 rgb(47, 126, 188) 80 rgb(24, 100, 170) 90 rgb(10, 74, 144) 100 rgb(8, 48, 107) >>> d3.interpolate_blues(0) 'rgb(247, 251, 255)' >>> d3.interpolate_blues(1) 'rgb(8, 48, 107)'
- detroit.scale_sequential_log() SequentialLog¶
- detroit.scale_sequential_log(interpolator: Callable[[float], float]) SequentialLog
- detroit.scale_sequential_log(domain: list[int | float], interpolator: Callable[[float], float]) SequentialLog
Builds a new sequential scale with a logarithmic transform, analogous to a log scale.
- Parameters:
domain (list[Number]) – Domain
interpolator (Callable[[float], float]) – Interpolator
- Returns:
Sequential object
- Return type:
Examples
>>> scale = d3.scale_sequential_log([1, 100], d3.interpolate_blues) >>> steps = 10 >>> for x in range(steps + 1): ... x = 2 * x / steps ... x = 10 ** x ... print(x, scale(x)) ... ... 1.0 rgb(247, 251, 255) 1.5848931924611136 rgb(227, 238, 249) 2.51188643150958 rgb(207, 225, 242) 3.9810717055349722 rgb(181, 212, 233) 6.309573444801933 rgb(147, 195, 223) 10.0 rgb(109, 174, 213) 15.848931924611133 rgb(75, 151, 201) 25.118864315095795 rgb(47, 126, 188) 39.810717055349734 rgb(24, 100, 170) 63.09573444801933 rgb(10, 74, 144) 100.0 rgb(8, 48, 107) >>> d3.interpolate_blues(0) 'rgb(247, 251, 255)' >>> d3.interpolate_blues(1) 'rgb(8, 48, 107)'
- detroit.scale_sequential_symlog() SequentialSymlog¶
- detroit.scale_sequential_symlog(interpolator: Callable[[float], float]) SequentialSymlog
- detroit.scale_sequential_symlog(domain: list[int | float], interpolator: Callable[[float], float]) SequentialSymlog
Builds a new sequential scale with a symmetric logarithmic transform, analogous to a symlog scale.
- Parameters:
domain (list[Number]) – Domain
interpolator (Callable[[float], float]) – Interpolator
- Returns:
Sequential object
- Return type:
Examples
>>> scale = d3.scale_sequential_symlog([1, 100], d3.interpolate_blues) >>> scale = scale.set_constant(2) >>> steps = 10 >>> for x in range(steps + 1): ... x = 2 * x / steps ... x = 10 ** x ... print(x, scale(x)) ... ... 1.0 rgb(255, 255, 255) 1.5848931924611136 rgb(253, 255, 255) 2.51188643150958 rgb(241, 247, 253) 3.9810717055349722 rgb(227, 238, 248) 6.309573444801933 rgb(210, 227, 243) 10.0 rgb(187, 215, 235) 15.848931924611133 rgb(154, 199, 225) 25.118864315095795 rgb(113, 177, 214) 39.810717055349734 rgb(75, 152, 201) 63.09573444801933 rgb(44, 123, 186) 100.0 rgb(19, 94, 165) >>> d3.interpolate_blues(0) 'rgb(247, 251, 255)' >>> d3.interpolate_blues(1) 'rgb(8, 48, 107)'
- detroit.scale_sequential_pow() SequentialPow¶
- detroit.scale_sequential_pow(interpolator: Callable[[float], float]) SequentialPow
- detroit.scale_sequential_pow(domain: list[int | float], interpolator: Callable[[float], float]) SequentialPow
Builds a new sequential scale with an exponential transform, analogous to a power scale.
- Parameters:
domain (list[Number]) – Domain
interpolator (Callable[[float], float]) – Interpolator
- Returns:
Sequential object
- Return type:
Examples
>>> scale = d3.scale_sequential_pow([0, 100], d3.interpolate_blues) >>> scale = scale.set_exponent(2) >>> steps = 10 >>> for x in range(steps + 1): ... x = 10 * x / steps ... print(x, scale(x)) ... ... 0.0 rgb(247, 251, 255) 1.0 rgb(245, 250, 254) 2.0 rgb(239, 246, 252) 3.0 rgb(229, 239, 249) 4.0 rgb(215, 231, 245) 5.0 rgb(195, 219, 238) 6.0 rgb(162, 203, 227) 7.0 rgb(112, 176, 214) 8.0 rgb(63, 141, 196) 9.0 rgb(22, 98, 168) 10.0 rgb(8, 48, 107) >>> d3.interpolate_blues(0) 'rgb(247, 251, 255)' >>> d3.interpolate_blues(1) 'rgb(8, 48, 107)'
- detroit.scale_sequential_sqrt() SequentialPow¶
- detroit.scale_sequential_sqrt(interpolator: Callable[[float], float]) SequentialPow
- detroit.scale_sequential_sqrt(domain: list[int | float], interpolator: Callable[[float], float]) SequentialPow
Builds a new sequential scale with a square-root transform, analogous to a sqrt scale
- Parameters:
domain (list[Number]) – Domain
interpolator (Callable[[float], float]) – Interpolator
- Returns:
Sequential object
- Return type:
SequentialSqrt
Examples
>>> scale = d3.scale_sequential_sqrt([0, 100], d3.interpolate_blues) >>> steps = 10 >>> for x in range(steps + 1): ... x = 100**2 * x / steps ... print(x, scale(x)) ... ... 0.0 rgb(247, 251, 255) 1000.0 rgb(176, 210, 232) 2000.0 rgb(129, 186, 219) 3000.0 rgb(92, 163, 208) 4000.0 rgb(65, 143, 197) 5000.0 rgb(45, 124, 186) 6000.0 rgb(29, 107, 175) 7000.0 rgb(17, 91, 162) 8000.0 rgb(11, 76, 146) 9000.0 rgb(8, 62, 127) 10000.0 rgb(8, 48, 107) >>> d3.interpolate_blues(0) 'rgb(247, 251, 255)' >>> d3.interpolate_blues(1) 'rgb(8, 48, 107)'
- class detroit.scale.sequential.Sequential(t: Callable[[int | float], T])¶
Sequential transformation
- Parameters:
t (Callable[[Number], T]) – Transform function
- __call__(x: int | float) T¶
Given a value from the domain, returns the corresponding value from the range.
- Parameters:
x (Number) – Input value
- Returns:
Corresponding value from the range
- Return type:
T
- set_domain(domain: list[int | float]) Sequential¶
Sets the scale’s domain to the specified array of numbers
- Parameters:
domain (list[Number]) – Domain
- Returns:
Itself
- Return type:
- set_range(range_vals: list[T]) Sequential¶
The given two-element array is converted to an interpolator function using interpolate
- Parameters:
range_vals (list[T]) – Two values
- Returns:
Itself
- Return type:
- set_range_round(range_vals: list[T]) Sequential¶
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_interpolator(interpolator: Callable[[float], T]) Sequential¶
Sets the scale’s interpolator to the specified function.
- Parameters:
interpolator (Callable[[float], T]) – Interpolator function
- Returns:
Itself
- Return type:
- set_clamp(clamp: bool) Sequential¶
Enables or disables clamping accordingly.
- Parameters:
clamp (bool) – Clamp value
- Returns:
Itself
- Return type:
- set_unknown(unknown: Any) Sequential¶
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.sequential.SequentialLinear¶
Linear sequential transformation
- 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.sequential.SequentialLog¶
Log sequential transformation
- 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:
- class detroit.scale.sequential.SequentialSymlog(c: int | float = 1)¶
Symlog sequential transformation
- Parameters:
c (Number) – Symlog constant value
- set_constant(c: int | float) SequentialSymlog¶
Sets the symlog constant to the specified number and returns this scale.
- Parameters:
c (Number) – Constant value
- Returns:
Itself
- Return type:
- class detroit.scale.sequential.SequentialPow(t: ~collections.abc.Callable[[int | float], float] = <function identity>)¶
Power sequential transformation
- Parameters:
t (Callable[[Number], T]) – Transform function
- set_exponent(exponent: int | float) SequentialPow¶
Sets the scale’s exponent value.
- Parameters:
exponent (Number) – Exponent 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: