gscatter - how to colour different marker styles according to a different variable?
Mostra commenti meno recenti
Hi,
I'm fresh to matlab (1 day) so be kind! I aiming to include 4 variables on a scatter plot. So far.....
The variables for X and Y each consist of random numbers (each 90x1 double) The marker style was set according to a 3rd (aka A) variable (also 90x1 double) whose value ranges from 1 to 3, essentially generating 3 series of data on the plot.
Using gscatter(X,Y,A,[],'ox+') I've generated the following plot which successfully plots different markers according to variable A. The problem is I'd like to use a 4th variable (B) to determine the color of each marker set. The variable B would again be (90x1 double) whose values might be incremental 1,2,3,4, etc.... or random. Can this be done and can you explain it in a way that takes pity on someone who has never used matlab or code before. I've heard it might be done with hold functions but I've no idea how to incorporate these.

2 Commenti
Brian Hunt
il 11 Set 2017
While this is old, I think it still deserves another answer for fixed number of types. If you want to group by two different things, one way to do so using gscatter in a loop as the following:
Suppose you have a group which you call A with 3 types and 3 colors. Suppose you also have a group called B with 5 types - 5 symbols.
%Create Vectors of 3 colors
clrs = ['rbk']
%Create Vector of markers with repeats length(A)
and indices how many different B you have.
syms = ['ooo','+++','ddd','xxx','sss']
for i=1:3 %Loop over colors
I = B == i
x = All_X(I)
y = All_Y(I)
for j=1:4
grp = A(I); %Anything that separates the A further
gscatter(x,y,grp,clrs,syms(j))
if(i==1 & j==1)
hold on
end
end
end
hold off
Warning: I didn't test this exact code for typos but have used this idea so the principle works.
Ali
il 29 Ott 2017
if true
--------------------------------------------------- code start
This is an example for your case
Input is "Input_Data", two dimension matrix
Marker_Counter=1;
figure6=figure;
Markers = {'+','o','*','x','v','d','^','s','>','<'};
for i=1:10:size(Input_Data,1)
TPR=Input_Data(i:i+9,7);
FPR=Input_Data(i:i+9,8);
plot(FPR,TPR,strcat('-',Markers{Marker_Counter}));
Marker_Counter=Marker_Counter+1;
hold on
end
plot([0.5 1],[0.5 1],'--');
legend('Minpts = 100','Minpts = 200','Minpts = 300','Minpts = 400','Minpts = 500','Minpts = 600','Minpts = 700','Minpts = 800','Minpts = 900','Minpts = 1000','','Location','SouthEast');
xlabel('FPR or (1-Specificity)','FontSize',12,'FontWeight','bold'); ylabel('TPR or Spensitivity)','FontSize',12,'FontWeight','bold');
title('ROC Space');
close(gcf);
-------------------------------------------- code end
end
--------------------------------------- picture link preview

Risposte (0)
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!