Plotting 4-D graph, 3-D with 4th dimension colored
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (1)
Cindy Solomon
el 7 de Mayo de 2015
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 comentarios
Bus141
el 7 de Mayo de 2015
Cindy Solomon
el 8 de Mayo de 2015
No problem- happy to help! =)
Abhishek Chopra
el 23 de En. de 2020
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
el 23 de En. de 2020
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.
Categorías
Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!