Keeping same colors for the same groups in different group scatter plot
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi!
I have a set of data containing around 5 000 000 different datapoints and these have been grouped into four different groups with the help of k-means clustering. When I plot these using gscatter, the four different colors presenting the datapoints belonging to each group in the plot are : group 1: purple, 2: blue, 3: orange and 4: yellow.
However, when I want to plot, for example, the first 100 000 of the datapoints they might only contain data belonging to group 1 and 3. Then the plot colours these as group 1: purple and group 3: blue instead of orange as in the original plot. How can I make it so the plots colours the datapoints based on the group they belong to?
Thank you in advance!
0 Commenti
Risposta accettata
KSSV
il 17 Mar 2023
P = rand(1000,2) ;
x = P(:,1) ; y = P(:,2) ;
idx = kmeans(P,4) ;
figure
h = gscatter(x,y,idx) ;
% Get colors
C = reshape([h.Color],3,[])' ;
figure
hold on
scatter(x(idx==1),y(idx==1),[],C(1,:))
scatter(x(idx==2),y(idx==2),[],C(2,:))
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Scatter 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!