I have two 1-D arrays of coordinates x and y and I would'l to have a density plot. I found that scipy.stats.gaussian_kde() could help me, but I don't undestand how it really work.
My code is:
n = 1000
xs, ys = np.random.normal(-3., 3., size=n), np.random.normal(1., 4., size=n)
x, y = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
positions = np.vstack([x.ravel(), y.ravel()])
values = np.vstack([xs, ys])
# Bandwidth value.
bw = 0.325
kernel = stats.gaussian_kde(values, bw_method=bw/np.asarray(values).std(ddof=1))
# Evaluate kernel in grid positions.
k_pos = kernel(positions)
kde = np.reshape(k_pos.T, x.shape)
Is "kde" the gaussian kernel density normalized between (0,1)? How can I get the density unnormalized to match to physical dimention for surface density as m^-2?
Thanks for your help!