Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

This is what it looks like

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

share|improve this question
    
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

up vote 2 down vote accepted

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

pic

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]

listPlot

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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