Kernel density estimation is a nice method to estimate the probability density function of an unknown distribution that produced the observed datapoints. It’s nonparametric, so we do not have to fit a specific model, and, provided that the shape of the kernel and its size (bandwidth) are sensible, works well.

opit wanted to use it, however, the standard Python implementations do not provide a way to incorporate weighted data – i.e. uncertainties or volume weighting factors.  As often happens, she found a solution on Stack Overflow (here’s the actual code).

This plot shows the brightness of some galaxies(M_r, in inverse log units) vs. logarithm of their rotation velocities. Since the galaxies have assigned weights to them (there are much more faint galaxies than big, bright ones), the majority of the points are not where the darkest region of the parent distribution is.