Scatter plot with multiple variables and colors

35 visualizaciones (últimos 30 días)
Sourish Mukhopadhyay
Sourish Mukhopadhyay el 16 de Jul. de 2021
Respondida: Bjorn Gustavsson el 16 de Jul. de 2021
Hi, I am trying to plot a scatter plot with 4 variables. It looks a bit like this right now.
X and Y are continuous variables, while Z and T are logical (0,1) variables. Each data point is basically a [X, Y, Z, T] vector. These data are in an excel file in tidy format.
I'd like to plot a scatter plot such that X,Y are on the axes, the dots or bubbles are a different color based on Z and a different size/symbol based on T. I can plot the scatter plot with just the X and Y fine now using just the scatter (X,Y) function, but have been having trouble customizing for the other variables in here. Any help will be appreciated. Happy to provide any more details or clarifications if that helps!
  1 comentario
dpb
dpb el 16 de Jul. de 2021
https://www.mathworks.com/help/matlab/ref/scatter.html#btrli6o-1 shows two examples to do precisely those things -- each just varies one of the two, size or color, but there's no reason you can't use both at the same time.

Iniciar sesión para comentar.

Respuestas (1)

Bjorn Gustavsson
Bjorn Gustavsson el 16 de Jul. de 2021
Something like this gives me 2 colours, and 2 sizes. You might modify the colours by switching colormap, size-mapping you'll have to modify to suit your needs:
scatter(randn(12,1),randn(12,1),10*(2+sign(randn(12,1))),sign(randn(12,1)),'filled')
HTH

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by