Link specific coordinates to a color when plotting them
20 views (last 30 days)
Hello I am wondering if there is a way to link specific coordinates in a matrix to always be plotted in a specific color. like if I had the set of coordinates shown below and i want the first 4 sets to always be plotted in red and the next 3 always plotted in green whenever they are being plotted so that even if I clear the axes and replot those coordinates will always appear in the color they were set to.
A = [38.8197976955836 -29.0434116907097
David Hill on 8 Sep 2019
red=[1 0 0];
green = [0 1 0];
color=[red;red;red;red;green;green;green];%make color array for the colors you want at each index
scatter(A(:,1),A(:,2),,color);%not sure what kind of plot you want
As long as the index does not change for the colors you want, then the above example should work.
More Answers (1)
Adam Danz on 8 Sep 2019
Edited: Adam Danz on 8 Sep 2019
When you use plot(x,y) it returns 1 handles and you cannot specify different colors to objects within the same handle.
You can use gscatter() (stats toolbox) to create grouped scatter points where you can specify the color (and size of markers) of each group.
h = gscatter(A(:,1),A(:,2),[1 1 1 1 2 2 2],[1 0 0; 0 1 0])
% _______________ here we define the groups by row
% ______________ here we define the colors for each group
If you don't have stats toolbox, you can separate the rows of A and plot them as individual objects.
h1 = plot(A(1:4,1),A(1:4,2), 'ro');
h2 = plot(A(5:end,1),A(5:end,2), 'go');