Scatter plot with multiple variables and colors

53 次查看(过去 30 天)
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 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by