Changing the color of specific points in a scatter plot

Hey,
I got some points in a 2-dimensional space from two different classes. I got a label vector to identify which points belong to which class. Now I would like to use this label vector, to change the color of the points belonging to the second class, after having made a scatter plot. How do I do this, without having to separate the code in two scatter commands?

 Accepted Answer

One of the inputs to the scatter function is a list of colors for the different data points. Just make it up however you'd like and pass it in.

4 Comments

Thanks, however this raises two new questions:
  • What format should the list be in? RGB or indexed? And if the latter, then how do I change what colormap it uses?
  • Is it possible to change this after creation of the scatter plot, using "set(h, 'Color', color_var);" or something like that?
First question doesn't make sense. Those aren't different. The colormap or color list is a list of colors in the form [r,g,b] where r, g, and b range from 0 to 1 and there are as many rows in that as you have data points, so that there is 1 color for every data point.
Second question, yes but why? I'm sure you can get the handle of every single datapoint on the plot and set its color with the set() command but why when you can just send in all the colors when you plot it.
I got it to work, thanks for the assistance. In case you're still curious on the second question: It is because the I'm making a program for classification. The classification isn't done initially, but rather when the user clicks a button. Hence the points should not change color until this time.
hey would you be able to share your code?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!