Scatter plot with multiple variables and colors

33 views (last 30 days)
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 Comment
dpb
dpb on 16 Jul 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.

Sign in to comment.

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 16 Jul 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

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!