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)

25 次查看(过去 30 天)

回答(1 个)

Steven Lord
Steven Lord 2016-11-2
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 个评论
Karin Ebenbeck
Karin Ebenbeck 2016-11-2
Thanks for this tip. But my problem is that the number of data changes time-dependent. First there are - let´s say - 15 data to plot and at the next time there are 28 or more. Furthermore I want to make a video with the different plots (with "VideoWriter"). This program is working - but now I need the "numbering" of the single markers. I tried following:
text (theta, rho+0.25, 'test')
with the result that the word 'Test' sticks on every marker. So I need your help again.
Steven Lord
Steven Lord 2016-11-2
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by