# ListPlot coloring by density of points

I have a set of points on a circumference:

points = Map[Normalize, RandomReal[{-1, 1}, {3000, 2}]]


And I want to plot them and color the plot according to the density of points. You see, ListPlot[points] will just give me that, a simple plot, on which I can't see the distribution of the points on the circle.

Maybe there is an option?

I hope you guys can understand what I'm asking.

Edit/Follow-up

I used SmoothDensityHistogram[points, ColorFunction -> "Rainbow"]

Now, it's not really what I'm looking for. I kind of wanted it to look like the original plot, just the circumference.

-
I think this question is different from the linked one here: How to create a heatmap from list of coordinates? so no need to close it... But basically the answer I give to that question is also applicable here. –  Jens Jun 27 '13 at 21:25
Thanks! I used SmoothDensityHistogram[points, ColorFunction -> "Rainbow"]. It's not really what I had in mind, but still does it for me. –  Iván Vladimir González Bustos Jun 27 '13 at 21:35
add comment

## 1 Answer

Here is what I think you wanted:

points = Map[Normalize, RandomReal[{-1, 1}, {3000, 2}]];

d = SmoothKernelDistribution[points];

colors = Hue /@ Rescale[PDF[d, #] & /@ points];

Graphics[Transpose[{colors, Point /@ points}]]


Here the SmoothKernelDistribution is evaluated in the plane, giving you a two-dimensional interpretation of density. One could also understand your question as asking for a one-dimensional density of points only on the circle. But I followed the simplest interpretation here.

For completeness, here is an implementation using ListPlot. The colors are contained in PlotStyle, but in order to make them apply to each point individually I have to add another level of depth to the list points:

ListPlot[Map[List, points], PlotStyle -> colors,
AspectRatio -> Automatic]


I may as well add the treatment of the density as purely one-dimensional on the circle: here I convert the elements of points to their polar angle coordinate, and then calculate the density in this polar angle:

arc = ArcTan /@ points;

d = SmoothKernelDistribution[arc];

colors = Hue /@ Rescale[PDF[d, #] & /@ arc];


Then proceed with the plots as above. One can of course play more with the options of SmoothKernelDistribution, depending on your application.

-
That's more like I want. A one-dimensional distribution on the circumference. –  Iván Vladimir González Bustos Jun 27 '13 at 21:45
If you want this to be completely one-dimensional, you would have to convert the coordinate tuples in points to arc length and apply SmoothKernelDistribution to the result. But the logic is the same as what I did above. Let me know if you want more details. –  Jens Jun 27 '13 at 21:46
Thank you very much! That's exactly what I wanted. –  Iván Vladimir González Bustos Jun 27 '13 at 22:10
add comment