2d Kernel Density Estimation


In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

import zsplot

Randomly generate gaussian elipse data


In [6]:
n_gaussians = 10
n_points = 1000

x = np.zeros(n_gaussians*n_points)
y = np.zeros(n_gaussians*n_points)

for i in range(n_gaussians):
    
    xcenter = np.random.uniform(0,10)
    ycenter = np.random.uniform(0,10)
    xwidth = np.random.rand()
    ywidth = np.random.rand()

    x_sample = np.random.normal(loc=xcenter, scale=xwidth, size=n_points)
    y_sample = np.random.normal(loc=ycenter, scale=ywidth, size=n_points)

    x[i*n_points:(i+1)*n_points] = x_sample
    y[i*n_points:(i+1)*n_points] = y_sample

Plot scatter plot


In [8]:
fig, axes = zsplot.kde2d(x,y, markersize=2)