Label each data point and color code the data points

38 views (last 30 days)
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!

Answers (1)

Kevin Joshi
Kevin Joshi on 9 Jun 2020
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

Tags

Community Treasure Hunt

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

Start Hunting!