Add data labels to scatter plot

71 ビュー (過去 30 日間)
Jake Welch
Jake Welch 2022 年 6 月 10 日
回答済み: Voss 2022 年 6 月 10 日
I have the code below, and i want to add a label with each data point. For the first data point, i want to label it '1', and second data point '2' and so on.
tenFootHorizontal = [2,3,-4.-1]
tenFootVeetical = [1,3,0,.5]
scatter(tenFootHorizontal,tenFootVertical,'red','filled');
xlim([-6 6]);
ylim([-10,10]);
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
  1 件のコメント
dpb
dpb 2022 年 6 月 10 日
See examples @<text> This should not be a difficult learning task...give it a go!!!

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

回答 (1 件)

Voss
Voss 2022 年 6 月 10 日
tenFootHorizontal = [2,3,-4,-1];
tenFootVertical = [1,3,0,.5];
scatter(tenFootHorizontal,tenFootVertical,'red','filled');
% make data labels:
text(tenFootHorizontal,tenFootVertical,sprintfc(' %d',1:numel(tenFootHorizontal)))
xlim([-6 6]);
ylim([-10,10]);
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by