how can I plot scatterplot using scatter or gscatter with different color for each variable

3 visualizaciones (últimos 30 días)
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;

Respuesta aceptada

Karim
Karim el 17 de Jun. de 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

Más respuestas (0)

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by