how can I plot scatterplot using scatter or gscatter with different color for each variable
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Farhad Abedinzadeh
am 16 Jun. 2022
Bearbeitet: Farhad Abedinzadeh
am 17 Jun. 2022
Hi, I am trying to plot some random variables(using gscatter and scatter) with different color
I also tried hsv for triplet RGB color for these functions,but it didn't work
could you please give me an instruction on how can I do that?
n = 200;
dat1=rand(n,1);
dat2=rand(n,1).*0.5;
dat3=-rand(n,1)*0.25;
0 Kommentare
Akzeptierte Antwort
Karim
am 17 Jun. 2022
I'm not completly sure if I fully understand the question.
But the 4th input for the scatter command can be used to indicate the collor.
See the example code below, hope it helps:
n = 200;
dat1 = rand(n,1);
dat2 = rand(n,1)*0.50;
dat3 = -rand(n,1)*0.25;
x_data = repmat((1:n)',3,1); % assume some x-data
y_data = [dat1;dat2;dat3]; % gather the y-data
c_data = repelem([1;2;3],n); % generate the color indices
figure
scatter(x_data,y_data,[],c_data,'filled')
grid on
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Scatter Plots 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!