how can I plot scatterplot using scatter or gscatter with different color for each variable
1 view (last 30 days)
Show older comments
Farhad Abedinzadeh
on 16 Jun 2022
Edited: Farhad Abedinzadeh
on 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 Comments
Accepted Answer
Karim
on 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 Comment
More Answers (0)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!