필터 지우기
필터 지우기

How can I solve the problem of colour map? (figure provided)

조회 수: 2 (최근 30일)
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2016년 5월 21일
댓글: Abdulatif Alabdulatif 2016년 5월 23일
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
Stephen23 2016년 5월 22일
편집: Stephen23 2016년 5월 22일
You are already specifying the color in the scatter call (the fourth argument). If you want to change the color then the easiest way is to correctly specify the input data to the scatter function.
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2016년 5월 22일
In case, I want to repeat this command four times. How can I specify a colour for each time a run the command?

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
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.
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

추가 답변 (1개)

Image Analyst
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
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);
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2016년 5월 23일
This is data structure: (x,y,c) c:refer to the class of the data points
(-9.69171, -8.86384, 0)
(-9.55902, -8.10946, 0)
(-1.73544, -7.12043, 1)
(-1.77755, -6.39318, 1)
(-3.79288, -5.00445, 2)
(-3.36182, -6.39692, 2)
(-1.46405, -1.70081, 3)
(-0.413965, -2.22041, 3)
(-9.59192, -8.78982, 4)
(-9.72115, -8.37142, 4)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Purple에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by