Assigning same color for same value at different plots
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Niraj Bal Tamang
am 24 Apr. 2022
Kommentiert: Niraj Bal Tamang
am 25 Apr. 2022
I have 3 tables.
For table1, x=[0.1 0.4 0.6 0.8], y=[0.2 0.3 0.7 0.9], name=[A B C A]
For table 2, x=[0.1 0.2 0.4 0.6 0.5 0.8], y=[0.2 0.5 0.3 0.4 0.7 0.9], name=[A B C A D E]
For table 3, x=[0.1 0.2 0.4 0.6 0.5 0.8 0.2 0.5 0.3 0.4 0.7 0.9 ], y=[0.2 0.5 0.3 0.4 0.7 0.9 0.1 0.2 0.4 0.6 0.5 0.8], name=[A B C A D E B C A D E B E B C A D]
I want to plot these points such that they have the same color and markertype assigned based upon their names for all three figures. I tried ploting them using gscatter plot with the 'name' as the group variable but the colors are different for same name in different figures. Can anyone please help me to assign same marker type and color for each name value and get a common legend for all three plots.
Thank You
0 Kommentare
Akzeptierte Antwort
Chunru
am 25 Apr. 2022
x{1}=[0.1 0.4 0.6 0.8];
y{1}=[0.2 0.3 0.7 0.9];
name{1}=["A" "B" "C" "A"];
x{2}=[0.1 0.2 0.4 0.6 0.5 0.8];
y{2}=[0.2 0.5 0.3 0.4 0.7 0.9];
name{2}=["A" "B" "C" "A" "D" "E"];
x{3}=[0.1 0.2 0.4 0.6 0.5 0.8 0.2 0.5 0.3 0.4 0.7 0.9 ];
y{3}=[0.2 0.5 0.3 0.4 0.7 0.9 0.1 0.2 0.4 0.6 0.5 0.8];
name{3}=["A" "B" "C" "A" "D" "E" "B" "C" "A" "D" "E" "B"]; % "E" "B" "C" "A" "D"];
% Colors & marker typescorresponding to the name A-E:
uname = ["A" "B" "C" "D" "E"];
lc = ['r' 'g' 'b' 'y' 'k'];
mt = ['o' '*' '^' 'v' 's']
for i =1 :3
subplot(1,3,i);
hold on
for j=1:length(lc)
idx = ismember(name{i}, uname(j));
plot(x{i}(idx), y{i}(idx), [mt(j) lc(j)], 'MarkerFaceColor', lc(j));
end
hold off
end
5 Kommentare
Chunru
am 25 Apr. 2022
The uname can be obtained:
uname = unique(name{1})
For lc (line color) and mt (marker type): Matlab has around 15 differnt types of marker and 8 types of color (doc plot). Then you can use different comnibation of them to make 20 different lc-mt. You may what to have an array such as
lcmt = ['rp' 'g<' ... 'ko']
Altrenatively if you do want to use different colors for different names, you can control the color individually. (For marker type, you have to recycle them for 20 names). For example
c = jet(20); % make 20 different colors from jet colormap (20*3 array)
plot(x{i}(idx), y{i}(idx), 'Marker', mt(j), 'MarkEdgeColor', c(j, :), 'MarkerFaceColor', c(j,:))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!