How can I scatterplot by group by the sign of the variable?

Hello!
I have data for two variables:
Capture.JPG
I wish to scatterplot the viarables such that when the variables have the same sign, lets say, both positive, the plot is filled. If they are not identical, they are not filled.
It will look something as this
Capture2.JPG
Thanks :-)

 Respuesta aceptada

Adam Danz
Adam Danz el 20 de Dic. de 2019
Editada: Adam Danz el 20 de Dic. de 2019
If you have the statistics and machine learning toolbox,
g = sign(var1)==sign(var2);
gscatter(x,y,g)
If you do not have access to gscatter,
g = sign(var1)==sign(var2);
scatter(x(g),y(g));
hold on
scatter(x(~g),y(~g));
In both cases, x, y, and g must have the same number of elements.

2 comentarios

EK
EK el 20 de Dic. de 2019
Sounds like a simple solution! Is the gscatter open source?
Well, none of Matlab's functions are open source. But if you have a matlab license gscatter is accessible to read.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Discrete Data Plots en Centro de ayuda y File Exchange.

Preguntada:

EK
el 20 de Dic. de 2019

Comentada:

el 20 de Dic. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by