Sampling Methods#
Sampling is a special technique of data transformation, which is built into Lets-Plot and is applied after stat transformation.
Sampling helps working with large datasets when unintentional attempt to plot an excessively large number of geometries can lead
to UI freezes and even to out-of-memory crashes. Sampling is also one of the ways of handling over-plotting.
from string import ascii_lowercase
import numpy as np
from lets_plot import *
LetsPlot.setup_html()
1. Random Sampling#
Random sampling selects data points at randomly chosen indices without replacement.
def data1(n, seed=123):
np.random.seed(seed)
cov = [[1, -.8],
[-.8, 1]]
x, y = np.random.multivariate_normal(mean=[0, 0], cov=cov, size=n).T
return dict(x=x, y=y)
Let’s set the size of data (n) that exceeds the default sampling threshold for points (100,000).
ggplot(data1(105000), aes('x', 'y')) + geom_point(alpha=.3)