Label each data point and color code the data points

Hello,
I have an XY scatter plot of 49 points, and I want to label each point according to a text. There are three classes of text (A, B and C) , and I would like to add the class to each point, and color code them for A, B and C. for example, for the first five datapoints:
X=[1 2 3 4 5]; Y= [2 4 6 8 10], and the labels would be [A A C B C]. I'd like to plot XY, with the datapoints colour coded acording to A, B and C., with a legend.
I looked up the documentation, and this is all I could find on multipoint text:
Text for Multiple Data Points
To display the same text at each location, specify txt as a character vector or string. For example, text([0 1],[0 1],'my text').
To display different text at each location, use a cell array. For example, text([0 1],[0 1],{'first','second'}).
For multiline text, use nested cell arrays. For example, text([0 1],[0 1],{{'first','new line'},'second'})
However, it wasn't quite clear to me how to apply this to my data. Could you help me with this please?
Thank you!

回答 (1 件)

Kevin Joshi
Kevin Joshi 2020 年 6 月 9 日

0 投票

You can use the following function to colour code groups (class) in scatter plot
To label each point use the text command,
https://in.mathworks.com/help/matlab/ref/text.html

1 件のコメント

Michel Nieuwoudt
Michel Nieuwoudt 2020 年 6 月 11 日
Thanks Kevin; though these links were not that helpful for me.

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

カテゴリ

タグ

質問済み:

2020 年 6 月 9 日

コメント済み:

2020 年 6 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by