how can I plot scatterplot using scatter or gscatter with different color for each variable
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Karim
2022-6-17
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!