Skip to content

sampling_random

sampling_random(
    n: int, seed: int | None = None
) -> FeatureSpec

Keep n rows chosen at random.

The kept rows keep their order. With the same seed the same rows are kept; without one a fixed default seed is used, so renders are reproducible. The rows are not the ones lets-plot picks. A layer with n rows or fewer is unchanged.

Parameters:

  • n (int) –

    Number of rows to keep, at least 1.

  • seed (int, default: None ) –

    Seed of the random generator.

Returns:

  • FeatureSpec –

    The sampling, for a layer's sampling=.

Raises:

Examples:

>>> import numpy as np
>>> from ggrust import *
>>> rng = np.random.default_rng(1)
>>> data = {"x": rng.normal(size=10_000), "y": rng.normal(size=10_000)}
>>> plot = ggplot(data, aes("x", "y")) + geom_point(
...     sampling=sampling_random(500, seed=42)
... )