Skip to content

sampling_systematic

sampling_systematic(n: int) -> FeatureSpec

Keep every k-th row, the smallest k that leaves at most n rows.

The first row is always kept, then every k-th row after it (k = ceil(rows / n)). A layer with n rows or fewer is unchanged.

Parameters:

  • n (int) –

    Largest number of rows to keep, at least 1.

Returns:

  • FeatureSpec –

    The sampling, for a layer's sampling=.

Raises:

Examples:

>>> import numpy as np
>>> from ggrust import *
>>> days = np.arange(100_000)
>>> data = {"day": days, "temperature": np.sin(days / 5_000) * 10 + 15}
>>> plot = ggplot(data, aes("day", "temperature")) + geom_line(
...     sampling=sampling_systematic(2_000)
... )