# How to apply color gradient in listplot based on the density of points

I have a list of points ( a list with sub lists which are {x,y} coordinates. I would like to have a listplot where the areas with higher density of points are in darker colors and areas with lower density of points have lighter colors so it is visually visible that in some areas points might overlap each other.

points = Join[
RandomVariate[
MultinormalDistribution[{-0.5, 0.25}, 0.07*IdentityMatrix[2]],
1000],
RandomVariate[
MultinormalDistribution[{0.6, -0.1}, 0.03*IdentityMatrix[2]],
1000],
RandomReal[{-1.5, 1.5}, {1000, 2}]
];
skd = SmoothKernelDistribution[points];
ListPlot[points,
ColorFunction -> Function[{x, y}, Hue[PDF[skd, {x, y}]]],
ColorFunctionScaling -> False, AspectRatio -> 1]

• You could also use GrayLevel[1 - PDF[skd, {x, y}]] for a monochromatic gradient. Or you could use Darker@Hue[...] instead. Commented Nov 10, 2020 at 15:22
• Thank you for your help. I was wondering how did you decided to use SmoothKernelDistribution ? Commented Nov 10, 2020 at 16:47
• Pjana the PDF of a SmoothKernelDistribution is the estimated probability density of the points. When the points are more densely compacted one would expect a higher probability density, and when they are more sparse, a lower probability density. You could visualize it with DensityPlot[PDF[skd, {x, y}],{x,-1.5,1.5},{y,-1.5,1.5}] Commented Nov 10, 2020 at 17:03
• thank you for the clarification Commented Nov 10, 2020 at 22:45
• Do you know how can I add a legend to this type of listplot? Commented Nov 11, 2020 at 18:10