How can I solve the problem of colour map? (figure provided)
2 次查看(过去 30 天)
显示 更早的评论
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?
4 个评论
采纳的回答
Stephen23
2016-5-22
编辑:Stephen23
2016-5-22
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.
clr = 'ymck';
for k = 1:4
...
scatter(x,y,a,clr(k))
...
end
0 个评论
更多回答(1 个)
Image Analyst
2016-5-22
The best way to do this is with gscatter() which does it automatically. If you have the Statistics and Machine Learning Toolbox, look it up in the help:
gscatter(x,y,group) creates a scatter plot of x and y, grouped by group. x and y are vectors of the same size. group is a grouping variable in the form of a categorical variable, vector, string array, or cell array of strings. Alternatively, group can be a cell array containing several grouping variables (such as {g1 g2 g3}), in which case observations are in the same group if they have common values of all grouping variables. Points in the same group and appear on the graph with the same marker and color.
4 个评论
Image Analyst
2016-5-22
Try this:
groups = ones(1,length(x));
groups(1:112) = 1;
groups(113:410) = 2;
groups(411:645) = 3;
groups(646:end) = 4;
gscatter(x,y,groups);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!