Plotting 4-D graph, 3-D with 4th dimension colored
显示 更早的评论
I am trying to plot a 3-D figure from 4 variables, the first 3 are semi-repetitive and the 4th one is the one from which I would like colors. In my actual set the 4th is not repetitive in any order but repetitive more randomly. Below is a generic code of my data looks like.
x=1:2:20; x=x'; x=[x;x;x;x;x;x];
y=ones(10,1); y=[y;y+1;y+2];y=[y;y];
z=ones(30,1)*2; z=[z;z+1];
c=1:4; c=c'; c=repmat(c,15,1);
scatter3(x,y,z,c,'filled')
As you can see from the figure it is hard to tell which dot is for which value of c. I am not set on using this graph if better ideas are out there. Any help is appreciated. Thanks!
采纳的回答
更多回答(1 个)
Cindy Solomon
2015-5-7
Hi Bus,
If your fourth dimension is only a small number of discrete values, I agree a legend would make more sense (Although you can make a colorbar with only 10 entries, a legend is probably a bit easier to read.)
You might have had some trouble creating different legend entries if you only had one plot object- it would be easiest to plot each c-value independently like you would when overlaying plots on top of each other with "hold on." For example, you could do something like:
cVals = unique(c); % Find all unique values of c
for i = 1:numel(cVals) % For every one of those unique values
indices = find(c == cVals(i)); % Find the corresponding indices
scatter3(x(indices),y(indices),z(indices),100,'filled') % Plot
hold on
end
legend('C = 1', 'C = 2','C = 3','C = 4');
to get the behavior that I think you are describing?
4 个评论
Bus141
2015-5-7
Cindy Solomon
2015-5-8
No problem- happy to help! =)
Abhishek Chopra
2020-1-23
Hi Cindy,
My problem is almost the same, except I have 1000 unique values. Is there a way that I could assign 1000 unique colors or a way to visualzie them better? Thank you!
Walter Roberson
2020-1-23
Humans have a hard time distinguishing that many colors. Realistically you should only use perhaps 25 colors. You can combine them with different line styles and marker shapes.
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!