【问题标题】:matlab plot with plot3 and scatter3 obscurring?matlab 绘图与 plot3 和 scatter3 模糊?
【发布时间】:2016-09-03 16:02:00
【问题描述】:

所以第一个情节:

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');

但没有问题。当我使用旋转工具旋转图形时,带有 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');

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

我找到了某种可行的解决方案:uistack(sc)

但它不起作用。

那么我到底应该怎么做才能使散点显示在第一个图中?非常感谢答案。这对我的硕士论文非常重要:D

【问题讨论】:

  • 所以当有不同z坐标的点时会出现问题:O
  • 你能上传能证明问题的图片吗?

标签: matlab plot matlab-figure


【解决方案1】:

我尝试了不同的方法。
我没有使用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 才能使其工作。

【讨论】:

  • 嘿,非常感谢! :) 它以我喜欢的方式工作。它对我来说足够高效:D 我仍然想知道如何(我认为它以某种方式可能)使它与 scatter3 一起工作。但这很好! :) 谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
  • 2014-08-20
相关资源
最近更新 更多