4
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Jens Jun 27 '13 at 21:25
  • $\begingroup$ Thanks! I used SmoothDensityHistogram[points, ColorFunction -> "Rainbow"]. It's not really what I had in mind, but still does it for me. $\endgroup$ – Ivan Jun 27 '13 at 21:35
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ That's more like I want. A one-dimensional distribution on the circumference. $\endgroup$ – Ivan Jun 27 '13 at 21:45
  • $\begingroup$ 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. $\endgroup$ – Jens Jun 27 '13 at 21:46
  • $\begingroup$ Thank you very much! That's exactly what I wanted. $\endgroup$ – Ivan Jun 27 '13 at 22:10

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.