Change properties in gscatter, based on the group label
6 ビュー (過去 30 日間)
古いコメントを表示
How to set some specific properties for a specific group (i.e. marker, markersize, one specific color), let's say for group labelled as "-1", and set the same properties (i.e. marker, markersize, except for colors, that should be different) for the remaining groups, i.e. groups labelled as "1,2,3,4"?
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];
g = gscatter(a(:,1),a(:,2),a(:,3));
I was thinking about something like this, but I do not know how to efficiently change properties in g = gscatter:
if unique(a(:,3)) == -1
'marker'=
'markersize'=
...
elseif unique(a(:,3)) ~= -1
'marker'=
'markersize'=
...
end
0 件のコメント
採用された回答
dpb
2023 年 11 月 1 日
編集済み: dpb
2023 年 11 月 1 日
load carsmall
subplot(1,2,1)
gscatter(Displacement,Horsepower,Model_Year) % default appearance
subplot(1,2,2)
hGSC=gscatter(Displacement,Horsepower,Model_Year); % original but save handles
hGSC(matches({hGSC.DisplayName},'70')).Color='k'; % set year 70 group color to black
0 件のコメント
その他の回答 (2 件)
Dyuman Joshi
2023 年 11 月 1 日
編集済み: Dyuman Joshi
2023 年 11 月 1 日
You can combine the other groups as one -
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];
g = a(:,3);
%Change the values of other groups to a random value that is not -1
g(g~=-1) = 3;
%To different groups
n=2;
%% Define parameters (I have taken values randomly)
%Colors
clr = [0 0 1; 1 0 0];
%Marker
m = [".", "*"];
%Marker size
ms = [12.5 5];
gscatter(a(:,1), a(:,2), g, clr, m, ms)
3 件のコメント
Dyuman Joshi
2023 年 11 月 1 日
編集済み: Dyuman Joshi
2023 年 11 月 1 日
@Sim, That can be adjusted as well -
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];
[g, q] = findgroups(a(:,3));
idx = q==-1;
n = numel(q);
%% Define parameters (I have taken values randomly)
%Colors
clr = hsv(n);
%Marker
m = repelem("*", 1, n);
m(idx) = ".";
%Marker size
ms = repelem(10, 1, n);
ms(idx) = 15;
gscatter(a(:,1), a(:,2), g, clr, m, ms)
Sim
2023 年 11 月 1 日
編集済み: Sim
2023 年 11 月 1 日
2 件のコメント
dpb
2023 年 11 月 1 日
You can always vote for others that helped; Votes aren't restricted to picking only one...and, there often are multiple ways to skin the cat or as here pieces can be taken from various solutions so the one "right" answer isn't always a palatable choice, true...
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!