I would like to mark the data points in a polarplot not only with circles but also with a number belonging to the single point (see figure below)
19 views (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157600/image.jpeg)
0 Comments
Answers (1)
Steven Lord
on 2 Nov 2016
The text function works on a polar plot created with polarplot. It would be trickier (but still possible) to do with polar. But if you're using a release that includes polarplot I recommend you use that instead of polar.
th = 2*pi*rand(1, 6);
r = 10*rand(1, 6);
polarplot(th, r, 'r+');
text(th, r+0.25, arrayfun(@num2str, 1:6, 'UniformOutput', false))
The 0.25 that I add to r in the text call is to offset the labels slightly from the points, so they don't overlap.
2 Comments
Steven Lord
on 2 Nov 2016
Okay.
numberOfPoints = 6;
th = 2*pi*rand(1, numberOfPoints);
r = 10*rand(1, numberOfPoints);
polarplot(th, r, 'r+');
You need to generate a cell array with numberOfPoints elements that are each char arrays. In the original example I posted I did that with arrayfun using the indices of each point's coordinates in the th and r vectors; let's do something different this time.
colors = {'red', 'blue', 'green'};
numberOfColors = numel(colors);
colorLabelPerPoint = mod(1:numberOfPoints, numberOfColors)+1;
text(th, r+0.25, colors(colorLabelPerPoint));
If I were to change numberOfPoints to a different value and rerun these two blocks of code, they would still work. The specific points that are plotted would be different, since the coordinates were generated using rand, but the code does not need to change.
You need to decide how to generate the labels on the points based on the number of data points that you're plotting. The first example used arrayfun, the second indexing into a cell array containing char vectors. Once you do that, calling text with the coordinates and labels will work.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!