Scatter plot with multiple variables and colors

조회 수: 8 (최근 30일)
Sourish Mukhopadhyay
Sourish Mukhopadhyay 2021년 7월 16일
답변: Bjorn Gustavsson 2021년 7월 16일
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
dpb
dpb 2021년 7월 16일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2021년 7월 16일
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

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by