5
$\begingroup$

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

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

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}
]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.