1
$\begingroup$

I have a list of data points to plot. These points all have the same radius of 1. The angles are different generally speaking, but it is possible some points can have the same angle, or the same angle after modulo 360 degrees. In that case, two points would overlap each other. For example,

data = {{0, 1}, {5 Pi/6, 1}, {8 Pi/3, 1}, {7 Pi/2, 1}, {10 Pi/3, 
    1}, {25 Pi/6, 1}, {6 Pi, 1}, {41 Pi/6, 1}, {20 Pi/3, 1}, {15 Pi/2,
     1}, {28 Pi/3, 1}, {61 Pi/6, 1}};

ListPolarPlot[data]

gives the following plot, which appears to be 6 points. Actually, they are 12 points and there 2 points overlapping each other everywhere.

enter image description here

My question is, how to label these points consecutively with numbers from 1 to 12 to indicate the sequence in which they appear in the data list and also change the marker of a point if it is overlapping a previous point? For example, the 7th point will be overlapping the 1st point in data, so its marker will be changed to a different shape than the dot, maybe an "x".

$\endgroup$

1 Answer 1

2
$\begingroup$

The following may look complicated, but the pattern for creating the counter in label is actually quite common and is good to learn (if you don't already know it.)

label[data_, acc_: 0.0001] := Module[{c},
  c[_] = 0;
  ++c[{
       Round[Mod[First[N@#], 2 Pi], acc],
       Round[Last[N@#], acc]
       }] & /@ data
  ]

labels = label[data];
groups = Map[Last, GatherBy[Transpose[{labels, data}], First], {2}];

ListPolarPlot[groups, PlotMarkers -> {"OpenMarkers", Large}]

Mathematica graphics

For labels, you can do:

first = First[groups];

Show[
 ListPolarPlot[first -> Range@Length@first],
 ListPolarPlot[groups, PlotMarkers -> {"OpenMarkers", Large}]
 ]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Thank you for the answer. To group the points is a great idea. With Mathematica 11.3, it seems that "OpenMarkers" is not recognized, but I understand markers can be specified anyway. There was another part of my question, though. That is, I would like to also have a number (1 to 12) to appear beside each point to show its sequence in the data list. Could you also help on that? $\endgroup$
    – nanjun
    Apr 23, 2019 at 15:48
  • $\begingroup$ @nanjun I've added an example about that. $\endgroup$
    – C. E.
    Apr 23, 2019 at 16:22
  • $\begingroup$ Thanks again, @C. E. I saw only the points corresponding to the first half of groups are labeled from 1 to 6. Actually, I intended to mark the points according to their original order in data and the numbers from 1 to 12 all need to be labeled, even when the 1st and 7th points may overlap each other. Is there a way to do that? $\endgroup$
    – nanjun
    Apr 23, 2019 at 16:42

Your Answer

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

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