3
votes

So first plot:

clear all; close all;
figure; hold on
points=[0 0 0; 0.5 0 0; 0.5 0.5 0; 0 0.5 0; 0 0 0];
plot3(points(:,1), points(:,2), points(:,3),'c','linewidth', 2);
scatter3(points(:,1),points(:,2),points(:,3),40,'filled','k');

yet no problem

Yet no problems. Points plot with scatter3 show always on top of the line plots when I rotate the figure with the rotation tool.

Now!!

When I plot:

figure;
hold on;
points=[0 0 0; 0.5 0 0; 0.5 0.5 0; 0 0.5 0; 0 0 0; ...
        0 0 1; 0.5 0 1; 0.5 0.5 1; 0 0.5 1; 0 0 1];
plot3(points(:,1), points(:,2), points(:,3),'c','linewidth', 2);
sc=scatter3(points(:,1),points(:,2),points(:,3),40,'filled','k');

problem occuring

And when I rotate the figure, the line plots are almost always on top of the scatter points (depending little bit from the angle), which is not what I want.

I have found some sort of solution which should work: uistack(sc)

It doesn't work though.

So what on earth should I do to make the scatter points show like in the first figure?? Thanks really much from the answer. This is really important for my master's thesis :D

1
so the problems occur when there is points in different z-coordinates :O - JeaBoy
Can you please upload images that demonstrate the problem? - Rotem

1 Answers

2
votes

I tried different approach.
Instead of using scatter3, I used spheres.
It's less efficient, and still not perfect... but I couldn't find a better solution.

Here is my code sample:

figure;
set(gca, 'xlim', [-0.005, 0.505], 'ylim', [-0.005, 0.505], 'zlim', [-0.005, 1.005]);

hold on;
points=[0 0 0; 0.5 0 0; 0.5 0.5 0; 0 0.5 0; 0 0 0; ...
        0 0 1; 0.5 0 1; 0.5 0.5 1; 0 0.5 1; 0 0 1];
plot3(points(:,1), points(:,2), points(:,3),'c','linewidth', 2);
sc=scatter3(points(:,1),points(:,2),points(:,3),40,'filled','k');


[x,y,z] = sphere(20);   %Returns the coordinates of the 20 by 20 sphere

for i = 1:length(points)
    x0 = points(i, 1);
    y0 = points(i, 2);
    z0 = points(i, 3);
    h_surf = surf(gca, x*0.004+x0, y*0.004+y0, z*0.004+z0, 'FaceColor', 'black', 'LineWidth', 2);
end

Note: I had to set xlim, ylim, zlim to make it work.

enter image description here