matlab情节与plot3和scatter3阻塞?

时间:2016-09-03 16:02:01

标签: matlab plot matlab-figure

首先是情节:

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

然而没问题。当我使用旋转工具旋转图形时,带有scatter3的点图总是显示在线图的顶部。

现在!!

当我画情节时:

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

当我旋转图形时,线条图几乎总是位于散点的顶部(取决于角度的一点点),这不是我想要的。

我找到了一些应该有效的解决方案:uistack(sc)

虽然它没有用。

那么我该怎样做才能使分散点像第一个数字一样显示?非常感谢答案。这对我的硕士论文来说非常重要:D

1 个答案:

答案 0 :(得分:2)

我尝试了不同的方法 我没有使用scatter3,而是使用了球体 它的效率低,但仍然不完美......但我找不到更好的解决方案。

这是我的代码示例:

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

注意:我必须设置xlimylimzlim才能使其正常运行。

enter image description here