MATLAB: How to solve the problem of colour map? (figure provided)

colormapdatsetStatistics and Machine Learning Toolbox

In the figure, the data is divided into four different groups and each group must be represented in different colour. however, I got a problem in the middle group which has the different colours in the same group.
How can I solve this problem?

Best Answer

Start by reading the scatter documentation. You can specify the color using the fourth argument, which is explained quite clearly in the documentation:
Marker color, specified in one of these forms:
  • Color string or RGB triplet — Plot all markers with the same color.
  • Three column matrix of RGB triplets — Use different colors for each marker. Each row of the matrix specifies an RGB triplet color for the corresponding marker. The number of rows must equal the length of x and y.
  • Vector — Use different colors for each marker and linearly map values in c to the colors in the current colormap. The length of c must equal the length of x and y. To change the colormap for the axes, use the colormap function.
One easy way would be to define (before the loop) the colorspec that you want to use:
clr = 'ymck';
for k = 1:4
...
scatter(x,y,a,clr(k))
...
end