Label index/variable name near data points

12 ビュー (過去 30 日間)
Nik Rocky
Nik Rocky 2020 年 6 月 15 日
編集済み: Adam Danz 2020 年 6 月 17 日
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!

採用された回答

Adam Danz
Adam Danz 2020 年 6 月 15 日
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 件のコメント
Nik Rocky
Nik Rocky 2020 年 6 月 17 日
Thank you very much! I used your first idea - its looks good!
Adam Danz
Adam Danz 2020 年 6 月 17 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by