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!