Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)

Respuestas (1)

Steven Lord
Steven Lord el 2 de Nov. de 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 comentarios
Karin Ebenbeck
Karin Ebenbeck el 2 de Nov. de 2016
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 el 2 de Nov. de 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.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by