ridgeplot._utils

Miscellaneous utilities and helper functions.

ridgeplot._utils.normalise_min_max(val, min_, max_)[source]
ridgeplot._utils.get_collection_array_shape(arr)[source]

Return the shape of a Collection array.

Parameters:

arr – The Collection array.

Returns:

The elements of the shape tuple give the lengths of the corresponding array dimensions. If the length of a dimension is variable, the corresponding element is a set of the variable lengths. Otherwise, (if the length of a dimension is fixed), the corresponding element is an int.

Return type:

Tuple[Union[int, Set[int]], ]

Examples

>>> get_collection_array_shape([1, 2, 3])
(3,)
>>> get_collection_array_shape([[1, 2, 3], [4, 5]])
(2, {2, 3})
>>> get_collection_array_shape(
...     [
...         [
...             [1, 2, 3], [4, 5]
...         ],
...         [
...             [6, 7, 8, 9],
...         ],
...     ]
... )
(2, {1, 2}, {2, 3, 4})
>>> get_collection_array_shape(
...     [
...         [
...             [1], [2, 3], [4, 5, 6],
...         ],
...         [
...             [7, 8, 9, 10, 11],
...         ],
...     ]
... )
(2, {1, 3}, {1, 2, 3, 5})
>>> get_collection_array_shape(
...     [
...         [
...             [(0, 0), (1, 1), (2, 2), (3, 3)],
...             [(0, 0), (1, 1), (2, 2)],
...             [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)],
...         ],
...         [
...             [(-2, 2), (-1, 1), (0, 1)],
...             [(2, 2), (3, 1), (4, 1)],
...         ],
...     ]
... )
(2, {2, 3}, {3, 4, 5}, 2)
>>> get_collection_array_shape(
...     [
...         [
...             ["a", "b", "c", "d"], ["e", "f"],
...         ],
...         [
...             ["h", "i", "j", "k", "l"],
...         ],
...     ]
... )
(2, {1, 2}, {2, 4, 5})
class ridgeplot._utils.LazyMapping(loader)[source]

Bases: Mapping[~_KT, ~_VT]

A lazy mapping that loads its contents only when first needed.

Parameters:

loader – A callable that returns a mapping.

Examples

>>> def my_io_loader() -> dict[str, int]:
...     print("Loading...")
...     return {"a": 1, "b": 2}
...
>>> lazy_mapping = LazyMapping(my_io_loader)
>>> lazy_mapping
Loading...
{'a': 1, 'b': 2}
_loader
_inner_mapping: Mapping[_KT, _VT] | None
property _mapping: Mapping[_KT, _VT]
_abc_impl = <_abc._abc_data object>