- For better visualization of functions of 4 variables, I recommend taking a look at sliceomatic
- For visualizing the fourth dimension specifically with color, you can change the size of the markers and/or colors of each point with scatter3. For example, if I replaced your last line with:
Plotting 4-D graph, 3-D with 4th dimension colored
78 views (last 30 days)
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];
c=1:4; c=c'; c=repmat(c,15,1);
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!
What sort of data are you trying to visualize? Without a specific idea, a few general recommendations for you:
markerSize = 100;
then the plot will now have data points whose color is the linear mapping of the values in C to the colors in the current colormap- the way you had it before was altering the size instead of color. If you would prefer to specify a RBG color value instead, you could also give it a 3 column matrix with the number of rows in C equal to the length of X, Y, and Z. This way, each row could then specify an RGB color value for each marker. This is especially handy if you want to change each marker separately (by size and/or color). You could also change the RGB value to be proportional to the value of c (ex: c/max(c)) as well.
Hope this helps!
More Answers (1)
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
legend('C = 1', 'C = 2','C = 3','C = 4');
to get the behavior that I think you are describing?