Change colors (of groups) in scatter plot
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
The following matrix contains around 80 rows, representing 2-dimensional points (each row corresponds to a point), and 3 columns, containing each point's x-coordinate, y-coordinate, and an integer number indicating the group to which the point belongs to, i.e. (-1, 1, 2, 3, 4). The latter integer number, i.e. (-1, 1, 2, 3, 4), comes from a clustering algorithm and it is taken by scatter(x,y,sz,c) to color all the points according to the belonging group. Now, how can I change the colors of the groups of points? I do not know what is the reference color set or color map used by scatter(x,y,sz,c), but can I change it, for example to c = turbo, or other color sets?
a = [37 98 1
35 94 1
33 97 1
33 99 1
31 96 1
30 97 1
29 100 1
30 94 1
31 90 1
28 93 1
21 63 1
20 61 1
22 60 1
24 60 1
24 64 1
27 62 1
28 65 1
27 59 1
23 57 1
26 56 1
27 57 1
29 57 1
31 60 1
31 61 1
31 64 1
32 66 1
36 60 1
37 56 -1
32 56 1
31 54 1
27 53 1
13 43 2
17 42 2
17 40 2
19 37 2
14 40 2
13 42 2
10 41 2
10 42 2
9 39 2
6 40 2
25 20 3
24 18 3
26 18 3
27 19 3
27 21 3
29 21 3
30 22 3
30 23 3
31 26 3
33 27 3
35 28 3
94 11 4
95 10 4
97 8 4
94 8 4
93 8 4
99 12 4
97 12 4
98 15 4
95 14 4
91 15 4
92 17 4
91 19 4
89 19 4
87 21 4
89 22 4
86 23 4
84 25 4
81 25 4
80 26 4
82 26 4
79 29 4
82 29 4
83 29 4
86 28 4
88 25 4
91 24 4
93 21 4
94 22 4
94 19 4
95 18 4
97 20 4];
scatter(a(:,1),a(:,2),[],a(:,3),'filled','s')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1525726/image.png)
0 Commenti
Risposta accettata
Rik
il 31 Ott 2023
As the documentation explains, you can set the colormap:
a = [37 98 1; 35 94 1; 33 97 1; 33 99 1; 31 96 1; 30 97 1; 29 100 1; 30 94 1; 31 90 1; 28 93 1; 21 63 1; 20 61 1; 22 60 1; 24 60 1; 24 64 1; 27 62 1; 28 65 1; 27 59 1; 23 57 1; 26 56 1; 27 57 1; 29 57 1; 31 60 1; 31 61 1; 31 64 1; 32 66 1; 36 60 1; 37 56 -1; 32 56 1; 31 54 1; 27 53 1; 13 43 2; 17 42 2; 17 40 2; 19 37 2; 14 40 2; 13 42 2; 10 41 2; 10 42 2; 9 39 2; 6 40 2; 25 20 3; 24 18 3; 26 18 3; 27 19 3; 27 21 3; 29 21 3; 30 22 3; 30 23 3; 31 26 3; 33 27 3; 35 28 3; 94 11 4; 95 10 4; 97 8 4; 94 8 4; 93 8 4; 99 12 4; 97 12 4; 98 15 4; 95 14 4; 91 15 4; 92 17 4; 91 19 4; 89 19 4; 87 21 4; 89 22 4; 86 23 4; 84 25 4; 81 25 4; 80 26 4; 82 26 4; 79 29 4; 82 29 4; 83 29 4; 86 28 4; 88 25 4; 91 24 4; 93 21 4; 94 22 4; 94 19 4; 95 18 4; 97 20 4];
scatter(a(:,1),a(:,2),[],a(:,3),'filled','s')
colormap('turbo')
Più risposte (1)
Image Analyst
il 31 Ott 2023
You should not be using scatter. You should be using gscatter (if you have the stats toolbox) which has the capability you are asking for.
Vedere anche
Categorie
Scopri di più su Data Distribution Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!