Stacks¶
- detroit.stack()¶
Builds a new stack generator with the default settings.
- class detroit.shape.stack.Stack¶
Builds a new stack generator with the default settings.
- __call__(data: list[T], *args: Any) list[Series]¶
Generates a stack for the given array of data and returns an array representing each series.
- Parameters:
data (list[T]) – List of data
*args (Any) – Additional arguments passed to
keysmethod.
- Returns:
List of series
- Return type:
list[Series]
- set_keys(keys: Callable[[...], list[str]] | list[str]) Stack¶
Sets the
keysmethod and returns itself.- Parameters:
keys (Callable[[...], str] | list[str]) – List of keys or function which returns a list of keys
- Returns:
Itself
- Return type:
Notes
The arguments of the function are the same as the additional arguments of
Stack.__call__method.
- set_value(value: Callable[[T, str, int, list[T]], float] | float) Stack¶
Sets the
valuemethod and returns itself.- Parameters:
value (Callable[[T, str, int, list[T]], float] | float) – Value number or function which takes the optional argument: data, key, index, list of data. The function must returns a float value.
- Returns:
Itself
- Return type:
Notes
You can pass a function with only the data and key arguments for example.
- set_order(order: Callable[[list[Series]], list[int]] | list[int] | None = None) Stack¶
Sets the
ordermethod and returns itself.
Stack orders¶
- detroit.stack_order_appearance(series: list[Series[T]]) list[int]¶
Returns a series order such that the earliest series (according to the maximum value) is at the bottom.
- Parameters:
series (list[Series[T]]) – List of series
- Returns:
List of ordered indices
- Return type:
list[int]
- detroit.stack_order_ascending(series: list[Series[T]]) list[int]¶
Returns a series order such that the smallest series (according to the sum of values) is at the bottom.
- Parameters:
series (list[Series[T]]) – List of series
- Returns:
List of ordered indices
- Return type:
list[int]
- detroit.stack_order_descending(series: list[Series[T]]) list[int]¶
Returns a series order such that the largest series (according to the sum of values) is at the bottom.
- Parameters:
series (list[Series[T]]) – List of series
- Returns:
List of ordered indices
- Return type:
list[int]
- detroit.stack_order_inside_out(series: list[Series[T]]) list[int]¶
Returns a series order such that the earliest series (according to the maximum value) are on the inside and the later series are on the outside. This order is recommended for streamgraphs in conjunction with
d3.stack_offset_wiggle.- Parameters:
series (list[Series[T]]) – List of series
- Returns:
List of ordered indices
- Return type:
list[int]
- detroit.stack_order_none(series: list[Series[T]]) list[int]¶
Returns the given series order \([0, 1, ..., n - 1]\) where \(n\) is the number of elements in series. Thus the stack is given by the key accessor.
- Parameters:
series (list[Series[T]]) – List of series
- Returns:
List of ordered indices
- Return type:
list[int]
- detroit.stack_order_reverse(series: list[Series[T]]) list[int]¶
Returns the reverse of the given series order \([n - 1, n - 2, ..., 0]\) where \(n\) is the number of elements in series. Thus, the stack order is given by the reverse of the key accessor.
- Parameters:
series (list[Series[T]]) – List of series
- Returns:
Order list
- Return type:
list[int]
Stack offsets¶
- detroit.stack_offset_expand(series: list[Series[T]], order: list[int])¶
Applies a zero baseline and normalizes the values for each point such that the topline is always one.
- Parameters:
series (list[Series[T]]) – List of series
order (list[int]) – List of ordered indices
- detroit.stack_offset_diverging(series: list[Series[T]], order: list[int])¶
Positive values are stacked above zero, negative values are stacked below zero, and zero values are stacked at zero.
- Parameters:
series (list[Series[T]]) – List of series
order (list[int]) – List of ordered indices
- detroit.stack_offset_none(series: list[Series[T]], order: list[int])¶
Applies a zero baseline.
- Parameters:
series (list[Series[T]]) – List of series
order (list[int]) – List of ordered indices
- detroit.stack_offset_silhouette(series: list[Series[T]], order: list[int])¶
Shifts the baseline down such that the center of the streamgraph is always at zero.
- Parameters:
series (list[Series[T]]) – List of series
order (list[int]) – List of ordered indices
- detroit.stack_offset_wiggle(series: list[Series[T]], order: list[int])¶
Shifts the baseline so as to minimize the weighted wiggle of layers. This offset is recommended for streamgraphs in conjunction with
d3.stack_order_inside_out.- Parameters:
series (list[Series[T]]) – List of series
order (list[int]) – List of ordered indices
Series¶
- class detroit.shape.series.Serie(values: list[float], data: T)¶
Point of a
Series- Parameters:
values (list[float]) – Point coordinates
data (T) – Data value associated to this point
- __getitem__(index: int) float¶
Returns the value of a specific index
- Parameters:
index (int) – Index value
- Returns:
Value
- Return type:
float
- __setitem__(index: int, value: float)¶
Sets the value at a specific index
- Parameters:
index (int) – Index value
value (float) – Value
- __len__() int¶
Returns the length of the serie
- Returns:
Length of serie
- Return type:
int
- __eq__(serie: Serie | Any) bool¶
Checks if another series value is the same as the current values.
- Parameters:
serie (Serie[T] | Any) – Other serie
- Returns:
True if two series are the same
- Return type:
bool
- __str__() str¶
Formats the class to a string.
- Returns:
String representing the current class
- Return type:
str
- __repr__()¶
Return repr(self).
- class detroit.shape.series.Series(series: list[Serie[T]] | None = None)¶
List of
Serieassociated to akeyand anindex- Parameters:
series (list[Serie[T]] | None) – List of series
- __getitem__(index: int) Serie[T]¶
Gets a serie given an index
- Parameters:
index (int) – Index value
- Returns:
Serie value
- Return type:
Serie[T]
- __setitem__(index: int, serie: Serie[T])¶
Sets a serie at a specific index
- Parameters:
index (int) – Index value
serie (Serie[T]) – Serie value
- __len__() int¶
Returns the length of the serie
- Returns:
Length
- Return type:
int
- __eq__(series: Series | Any) bool¶
Checks if another series value is the same as the current values.
- Parameters:
series (Series[T] | Any) – Other series
- Returns:
True if two series are the same
- Return type:
bool
- __str__() str¶
Formats the class to a string.
- Returns:
String representing the current class
- Return type:
str
- __repr__()¶
Return repr(self).