# Plotting points with different colors according to their local density

I have the position of some points in the 2D plane. How can I plot points in the 2D plane, with different colors so that, each color shows the local density of points? I need denser points to be in different color comparing with lower dencity points

• This: 6081 or that: 27786? – Kuba Nov 10 '17 at 7:54
• Is there a way to show a unit vector in the position of each particle? @Kuba – Oliver Range Nov 10 '17 at 8:40
• Yes they are. thank you for the links/ – Oliver Range Nov 10 '17 at 8:41
• How can I show larger points?@Kuba – Oliver Range Nov 10 '17 at 8:43

If not those links then probably this:

data = RandomVariate[BinormalDistribution[.75], 50];

d = SmoothKernelDistribution[data];

colors = Rescale[#, MinMax[#], {0, 1}] & @ PDF[d, data];

Graphics[
{AbsolutePointSize@12,
Point[data, VertexColors -> (Blend["TemperatureMap", #] & /@ colors)]
}
]


You can play with bandwidth:

data = RandomVariate[BinormalDistribution[{0, 0}, {.4, .7}, .5], 200];

Animate[
d = SmoothKernelDistribution[data, 10.^bw]
; colors = Blend["TemperatureMap", #
] & /@ Rescale[#, MinMax[#], {0, 1}] & @ PDF[d, data]

; Graphics[{
Inset[Style[NumberForm[10.^bw, {∞, 2}], Bold, 18], Scaled[{.2, .8}]]
, AbsolutePointSize@12, Point[data, VertexColors -> colors]
}
, Frame -> True
, PlotRange -> 2
, ImageSize -> 500
, Background -> Black
, FrameStyle -> White
]
, {bw, -2, 1, .2}
]


• – Kuba Nov 10 '17 at 9:51