MATLAB Answers

I have a scatterplot where the points are colored by group number. How do I add a legend with the group color attached?

26 views (last 30 days)
I have a scatter plot with each point colored by it's cluster number (ranging from 1 to 5) and I'm trying to add a legend that will indicate which color belongs to which group.
scatter(Data.X, Data.Y, Data.ClusterNumber); legend(strcat('Group: ', num2str(transpose(1:5))))
The above gets me the scatter plot and legend, but there is only a single dot for all 5 clusters.

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 26 Jan 2018
If you have the Statistics and Machine Learning Toolbox, it is probably easier to use the gscatter (link) function.

More Answers (0)

Sign in to answer this question.