Label index/variable name near data points

14 Ansichten (letzte 30 Tage)
Nik Rocky
Nik Rocky am 15 Jun. 2020
Bearbeitet: Adam Danz am 17 Jun. 2020
Hello I,m looking for solution to print a index near to data point:
The example values are:
M =
2278 2 685 2
197 2 2221 2
524 2 2496 2
1061 2 3415 2
651 2 5810 2
1105 2 3817 2
276 2 4527 2
I want to have a text box near to (2278,2) 1; (197,2) 2 .....
lables = 1 %lables = (1:k)
figure('Name','Result','NumberTitle','on');
hold on
p11 = plot(M(:,2),M(:,1),'ro','Color','g');
hold on
p12 = plot(M(:,4),M(:,3),'rx','Color','r');
text(M(:,4),M(:,3),labels,'VerticalAlignment','bottom','HorizontalAlignment','right')
xlabel('tube dimension')
ylabel('Results')
tube_size_help = sprintf('%.0f',tube_size);
nameX=strcat(name ,'_tube_size_',tube_size_help);
saveas(gcf, [nameX '_results.png'])
But I get everythere the same value. Hov can I insert a changing index of row near to M(row,2),M(row,1) (or names of measures)
for loop? Or somethink better?
Thank you!

Akzeptierte Antwort

Adam Danz
Adam Danz am 15 Jun. 2020
This is easy with labelpoints() found on the file exchange.
figure('Name','Result','NumberTitle','on');
hold on
p11 = plot(M(:,2),M(:,1),'ro','Color','g');
hold on
p12 = plot(M(:,4),M(:,3),'rx','Color','r');
labelpoints(M(:,4),M(:,3), 1:size(M,1), 'E', 0.2)
% "E" means "east" of the coordinate
% 0.2 is a buffer space between the label and the marker
  6 Kommentare
Nik Rocky
Nik Rocky am 17 Jun. 2020
Thank you very much! I used your first idea - its looks good!
Adam Danz
Adam Danz am 17 Jun. 2020
Good! I should also mention that you can click-and-drag the labels after they are plotted, too, in case you need to make final adjustments to a figure you intend to present or publish.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by