6
$\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$
4
  • 1
    $\begingroup$ This: 6081 or that: 27786? $\endgroup$
    – Kuba
    Commented Nov 10, 2017 at 7:54
  • $\begingroup$ Is there a way to show a unit vector in the position of each particle? @Kuba $\endgroup$ Commented Nov 10, 2017 at 8:40
  • $\begingroup$ Yes they are. thank you for the links/ $\endgroup$ Commented Nov 10, 2017 at 8:41
  • $\begingroup$ How can I show larger points?@Kuba $\endgroup$ Commented Nov 10, 2017 at 8:43

1 Answer 1

7
$\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$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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